Sunday, October 04, 2009
The Problem scenario is like this:
I have a button and a textbox on a asp.net page:
<asp:Panel ID="Panel1" runat="server"
<asp:TextBox ID="GroupName" runat="server" Width="352px” />
<asp:Button ID="CreateGroup" runat="server" Text="Create"
onclick="CreateGroup_Click" />
</asp:Panel>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />
When I click the button a label should be added dynamically to the placeholder located in the page:
The code in click event handler is as:
protected void CreateGroup_Click(object sender, EventArgs e)
{
Label label = new Label();
label.Text = GroupName.Text;
label.ID = GroupName.Text;
PlaceHolder1.Controls.Add(label);
}
Its working but the problem is only last label are added to placeholder not the previous ones like:
If I put “Computer” in texbox and click,then the label is added .fine.
But If I put again “science” and click,then the label with “science” is added but the previous label is not rendered.
Any guesses,solutions?
Well..here are some workarounds:
You can use this:SEE THE EXPLANATION WHY ITS HAPPENING:
http://igregor.net/post/2007/12/24/Adding-Controls-to-an-ASPNET-form-Dynamically.aspx
Or this:
http://stackoverflow.com/questions/113392/dynamically-added-controls-in-asp-net
http://www.4guysfromrolla.com/articles/092904-1.aspx
Or the best solution is
Avoid dynamically creating controls.Actually creating controls dynamically is not the problem but maintaining there state might be.
Instead of storing dynamically added controls in ViewState,
You can use a collection to store them and store it in ViewState[Updated] . But I would again say,Avoid such things as much as possible..
If you get any better workaround ,Please do point me to that.
In my opinion,The best Solution will be the solution which will add the controls just like they are added at design time.But design time is different than runtime..Which occurs after compilation.
Please read the second comments that follows this post(Some nice cons of static variables in ASP.Net pages).
I am pasting here as i really liked the "Disadvantages of static variables in ASP.NET"
"You can use a collection to store them and declare it as static" I need to caution against this. I have learned some hard lessons with this.
I have many developers use static variables in their ASP.NET pages and NOT realize thast every user shares that variable.
If I have static array of strings that a button click adds to, and I have 2 users click that button, there will be 1 array 2 items in that array. A page where this is the intended affect desireable is rare.. and probally badly designed :).
The implications of adding a Control as a static member would be much, much worse. (GC collection and a threading nightmare!)
Storing Meta data using a client-specific storage, like Viewstate may be the way to go.
Tuesday, July 21, 2009
If you ever tried to make irregular windows in wpf and used setting windowstyle=none,You might have used some code like this to enable minimising,maximising properties for the window:
private void Minimize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void Maximize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Maximized;
}
But on maximizing ,the window hides the taskbar.i.e it goes fullscreen.
To avoid that issue,You can use this code and yes,it works like a charm.
http://blogs.msdn.com/llobo/archive/2006/08/01/Maximizing-window-_2800_with-WindowStyle_3D00_None_2900_-considering-Taskbar.aspx
public override void OnApplyTemplate()
{
System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
}
private static System.IntPtr WindowProc(
System.IntPtr hwnd,
int msg,
System.IntPtr wParam,
System.IntPtr lParam,
ref bool handled)
{
switch (msg)
{
case 0x0024:/* WM_GETMINMAXINFO */
WmGetMinMaxInfo(hwnd, lParam);
handled = true;
break;
}
return (System.IntPtr)0;
}
private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
{
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
// Adjust the maximized size and position to fit the work area of the correct monitor
int MONITOR_DEFAULTTONEAREST =0x00000002;
System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitor != System.IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
}
Marshal.StructureToPtr(mmi, lParam, true);
}
As seen above the code basically handles the WM_GETMINMAXINFO message. The sample project code is also included. Have Fun. :)
Update: A better way to get the handle to the window is to use the SourceInitialized event. This would also avoid calling ApplyTemplate everytime the window template is changedon the fly. Thanks to Hamid for pointing out the better solution. The attached project is now updated.
win.SourceInitialized += new EventHandler(win_SourceInitialized);
void win_SourceInitialized(object sender, EventArgs e)
{
System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
}
College is opening tommorow and I am thinking what i have done in past 1 and half months of vacations.
The only thing i can remember is bluz,my open source project.
Where is that p2p thing i decided earlier?
All the research papers about skype,overlay networks ,guntella etc are lying there on disk as it is.i have read them only once.I have read not understood..
The positive side of vacations is:
1)I learned a lot about WPF,Blend etc.
2) I am participating in win7 contest based on above experience.
3)I met shaun,my new co-developer of bluz..
4)I have got some books of ASP.Net by bill ,scott and WPF book by Mathew macdonald..
And now i have some web 2.0 ideas that i hope to implement as a way of parcticing this ASP.net stuff.Thats a business idea,So you might see something interesting on web soon.
So,If i look back that way,I think it was more rewarding than any of internship i could get.
Now ,its my last year of graduation,My targets include:
1)Enjoy it fully.I know thats hard but i'll have to make this year remeberable .
2)Implement business ideas.(I love making money in humanatic way).
3)Make final year Project.
The 3rd one is where i'll cut my efforts ,Becoz i don't think that really matters as compared to my learning.Also,I don't see potential partners for a cool. .Net team to make a cool project at the college.
cya guys,
cheers
Hii guys,
Just heard about this
https://www.code7contest.com/
If you have a little experience with MS .Net and you are as empty as me,Have a look over it.
The prizes are awesome and mouth watering .You will have to grasp a little about the windows 7 techonolgies though .But you can do that for atleast 17777$.
I am getting ready with a killer app idea..yes it is a a killer idea,Either it will Kill MS or my Laptop.lol!(Sorry bill,its a metaphor,don't take it serious.)
And the best thing is that ,My Last 2-3 months of WPF experience is what gonna be tested.
The deadline is short but thats good for me ,I am entering with an optimistic mind,Hope to see you guys at LA soon..
cheer with a beer.(I don't drink though)
Wednesday, July 15, 2009
hi guys.
I have just released a pre beta release of next generation media player bluz.
Link is here:
http://code.google.com/p/bluz/
Its based on vlc libraries and bass and a couple of others for various tasks.
Its in c#,WPF but if any of you would like to contribute through any means.
The UI is purely in XAML,I am not a good designer,Even all icons are made in XAML.
.
If any of you would like to contribute through coding various modules or helping me develop the website,it would be nice of you to make it a hit on windows OS.
Atleast,U guys can check out and report any bugs you find to me directly..
It requires .Net 3.5
Have a nice day.
Screenshots:


Thursday, June 11, 2009
I have moved the tagging features for my media player application from MediaInfo to taglib-sharp.
because taglib-sharp provides writing of tags back to audio files too..
As a matter of fact,
Everything else was fine but,it took me whole half day to figure out how to display an image (album art) from taglib-sharp.
I thought to finally post this workaround.
TagLib.File file = TagLib.File.Create((FilePath); //FilePath is the audio file location
TagLib.IPicture pic=file.Tag.Pictures[0]; //pic contains data for image.
MemoryStream stream = new MemoryStream(pic.Data.Data); /create an in memory stream
Image im = new Image();
BitmapFrame bmp = BitmapFrame.Create(stream);
im.Source = bmp;
now u can use this image as a normal image..:)..i.e transformation,animation should be possible as usual.
cheers, i didn't got any post on web till now even after searching Novell's Repositories..Hopefully it helps to somebody out there .
Sunday, May 03, 2009
This is in continuation to my last post in which i was confused of "what to do in summers".
After a lot of thinking,I have got the answer.
I'll study/research on
"p2p architectures and there use in enterprises"...Lets see how it goes,i have semester exams next week and i have downloaded a lot of books/technical papers to get started. ..
p2p will help me distinguish my music player from others in the market...
I'll also look at using the p2p library
"Brunet" which is not much publicized as gnutella ...You can see the work here:.
.
http://github.com/johnynek/brunet/tree/master
Its a work by Sir ,Oscar BoyKin at UCLA(University of California)..For a weath of softwares and knowledge/he blogs at:
http://boykin.acis.ufl.edu/
I'll make my player a true web 2.0 social app..doing some homework in p2p architectures will be good for my summers...
And I'll keep posting tuts/links or any cool things that i'll encounter in my p2p research.I am really excited for it.
Have a happy coding.
Thursday, April 16, 2009
I am a Computer science student and there is a big Question mark of what i'll do in summers.
Ofcourse,I have some projects to do ,But even then i would like to get some internship.A fun and learning opportunity at the same time,i can earn too..
But this recession has really affected my internship hopes..
Companies like Microsoft,Google are giving paid internships to Phd Students only and i am a pursuing undergraduate from not so famous college.
..And they require some big references which i am not having.
What may be other cooler options..?Let me think over it ..hmmm..
Tuesday, April 14, 2009
Hey all,
I can't imagine how easy it can be to develop and maintain a plugin architecture with System.AddIn and this tool
VSPipelineBuilder.. This is a visual studio addIn is an open source project by the ClrAddIn team and is really awesome.
U just define an interface/Contract and rest of the things, just a single click through that addIn.
AddIn will implement that Interface and thats it,u can use it..Cheers .........
I used it for first defining a single interface .and implemented a small AddIn.
.
then i added 2-3 interfaces and re executed that VSPipeline Builder AddIn..And it was awesome to see that every project in The Pipeline(4-5 projects) got updated accordingly.
My old AddIn was still working becoz its contract was still there..
And iwas ready to implement new AddIns..Really great...It can save a lot of time when u have a lot of contracts to support various plugins/AddIns.
Below is a screenshot of an excellent demo app from jesse kaplan:
It demonstrates visual addIn also(Passing UI objects between AddIn and host)
ClrAddIn Team blogs at:
http://blogs.msdn.com/clraddins/
U can download the VSPipeline Builder from here:
http://clraddins.codeplex.com/
Cheers,And thanx to Jesse kaplan and the whole ClrAddIn team.
Friday, April 10, 2009
Hey everyone,I am writing this so that anyone can point me to some good articles,tutorials on creating a plugin support for an application in .Net 3.5 or higher(SP1).
I tried a lot of google searches but nothing that can let me create plugin support for my application in a standard way...
Thanx in advance.