Saturday, February 19, 2011

How to use different target framework in Visual Studio 2010

In VS 2010 there is one beautiful feature wherein you can execute your legacy applications along with your new apps. This is possible because of the multi-targeting feature available in VS 2010.

Now you can decide which .Net Framework to use for your code through VS 2010.
Just Go to Solution Explorer -> Properties -> Build -> Target Framework.

You're done with it !!!

How to fetch value from dynamically created control

There are some cases wherein you can not create the controls to display data at compile time. For example, displaying values from a Hashtable in a TextBox control, you never know how many key-pairs you are going to deal with (provided the Hashtable contains dynamic data). The logic for displaying the data is pretty much simple. You create an array of TextBoxes or any other control to display the data and you are done with it.

But the main problem lies in fetching the data which might have got changed from the UI. If you try to find out the TextBox controls from Page.FindControl() you won't be able to do so, thats because there isn't any markup for the FindControl() to look for and thats why it will always be null.

So to tide over your problem you can simple fetch the value from just one line

Request.Form[yourcontrolID]

The Request object as we all know is base of the web architecture. So whatever is being communicated between client and a Server has to have its presence in the Request object. Technically speaking whatever controls you can find in the html markup of you page on the client side will be available in this Request object.

Happy Coding :)