ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

This page lists some of the more popular “ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas” posts I’ve done. My goal is to add new posts to the series regularly going forward – so bookmark this page for updates, or subscribe to my blog via this RSS feed.

Book Recommendations

In addition to my articles below, I highly recommend the following ASP.NET books:


To learn more about ASP.NET, also make sure to watch all of the great “ASP.NET: How Do I?” videos (each week a new video is posted). You can also browse a large listing of other ASP.NET 2.0 books here

Visual Studio 2005







.NET 3.5 and VS 2008

LINQ and .NET 3.5




  • This is awesome! It save us time digging around your blog :-) Keep up with the good work!

  • Nice post.. I have only just come across your blog and what I have read so fair has been very helpful.

  • Your blog is so good and filled with interesting things that its a daily task for me to take a peek at for new posts!

    Keep it up!

  • Scott,
    Terrific...It's an awesome list and very helpful references. You're great! Thanks a lot.

  • Hi,

    just wondering if there are any articles on MSDN on how to tackle 2 way data binding on complex objects aka composite objects?

    Seems to be a bit of a black hole in terms of documentation or at least my ability to find it.


  • Hi Daniel,

    For tutorials on 2 way databinding, I'd recommend checking out this tutorial series: as well as the quickstart samples on data:

    Hope this helps,


  • Hi Scott,

    Thanks for the quick reply. I have seen these articles and they all use typed data sets. I have a collection of complex objects that I am binding to.

    if I have Simple properties such as Person.Name then it works fine, no problems, however if I have a property that is an object and I try to access its properties, i.e Person.Address.Postcode then databinding fails.

    I have worked around this by handling the objectdataSource Updating event and adding the values into the object manually however I was wondering / hoping that there is a better solution for this?


  • Hi Dan,

    You can do 1 way evaluation of complex objects using the syntax:

    Unfortunately two-way binding of sub-properties via the syntax isn't supported though. For these types of operations you'd want/need to use the event approach you mentioned above.

    Hope this helps,


  • Hi scott,
    one problem i always face is the treeview state in a masterpage. It never keeps its state and the nodes get collapsed. Is there any article on how to keep the state?

  • Hi Chris,

    One approach you could take would be to add a Page_Load event handler within the master-page, and use it in conjunction with the SiteMap API to expand the current node in the site that you are visiting.

    Hope this helps,


  • Hi Scott,

    I want to know whether the use of data source control provided with ASP.NET 2.0 are better than the hand coding or not.I am little confuse about this.....

    What should i use Data Source Control or Hand Coding.(Pros & Cons of both).

    As with coding transaction management is easy but is it easy or necessary with Data Source Controls like (SQLDataSource Control or AccessDataSource Controls)

    If u can please tell me with some experimental approach...........

  • Hi Scott,

    Please tell me that if is there any issue(Web Hosting) in using
    ATLAS extender or controls instead of ASP.NET 2.0 normal controls.

    Please tell me that ATLAS is supported by normal ASP.NET 2.0 hostings???????

  • Hi Jai,

    Atlas Control Extenders are fully supported with hosting scenarios.

    Hope this helps,


  • Hi Jai,

    DataSourceControls basically encapsulate the code you'd otherwise write by hand. So if you still want to write it by hand you can definitely continue to-do so.

    Hope this helps,


  • Hi Scott,

    I have a problem related to Login System.

    I am developing 3 websites for some institution.Now they want that if anybody had sign up for there, than he or she should be able to sign in for and

    hence, if user has sign up for the membership of than he/she should automicallly become the member of and
    also if the member sign in for the and if opens or than there he/she must be shown as "Already Login"

    Anybody Please tell me how can i make a Login System(with 1000% security) which is available to mulitple websites.

    If possible give some reference also......

    Thanks in advance.........

  • Hi Jai,

    I believe what you are looking for is a single-sign-on (SSO) solution. That way the user doesn't have to sign-in to other sites.

    I've haven't used these two links myself, but below are two articles that might help:

    Hope this helps,


  • Its Nice and very Intresting to read all the Articles.its a good link which is to added in favorites...

  • Hi Scott,
    I've quick question regarding the asp:treeview in VS2005. I'm a novice to VS2005, i am trying create a custom treeview by inheriting the WebControls.Treeview, everything work fine except when a parent node is clicked it doesn't expand the child node. It gives me the following error.

    'childNodes.0' is null or not an object

    I checked the viewsource and found out that each node is given an ID, if it as a parent-child relation.

    Please help me.


  • I need help with xp_cmdshell, using VWD2005 and SQL2005 Express Edition. Despite enabling this feature using the surface area configuration, I still cannot run a stored procedure using xp_cmdshell. Any idea what I could be doing wrong? Thanks in advance.

  • Hi Scott, If both C# and Code is there,fine and Its a good link which is to added in favorites...

  • Scott,
    I am trying to use Javascript to resize a gridview control vertically as a user resizes a web page vertically with his mouse. Can you point me in the right direction for that?

    Ray Levron

  • Hi Ray,

    Unfortunately I don't know off the top of my head of a sample that does this.



  • Hi scott ure posts have been a great help. just need to ask ya, how to batch update through a datlist control, without using business layers as shown on the tutorials on te website and instaed of the the northwind mdf database iam using sql server 2005. Any help or directions towards tutorials would be great. just to let u know iam a beginner at 2.0



  • Hi Scott, I wan to make my own Treeview control has the same behavior like one appears when i install VS .net 2005, i mean when i check a treenode with children... they all appears checked too, and if the parent is unchecked... and then i checked one of its childs... parent treenode get checked but with gray color. I know that when i check or uncheck a treenode althougth i had set OnCheckChange method... it will not do anything till i do a postback action like a simple button. So... how could i do this? thanks...

  • Hi Scott. Your blog is a great resource and as i am new to, it has helped me in many ways. I have one question to ask, I have a master page that uses
    some images and a css file that are placed in root\images folder. if i use deny users="?" in root web.config and go to login.aspx, the master page is loaded but without images or css styles. I have to place a web.config in the images folder with allow users="*" to make master page work correctly. Is my solution correct or is there something i have missed? or is there a better/recommended way to do it?

    Shouldn't allow master pages to load resources from subfolders even with anonymous user?

  • Hi ARC,

    I believe this blog post will fix your problem:

    Hope this helps,


  • What is the maximum allowed post length? I've tried to post 3 times now. I receive no error message, but it doesn't appear even after 16 hours.

  • Hi Nathaneal,

    The maximum post length by default is about 2MB. You can configure it to a larger size within the maxRequestLength property on the section within your web.config file.

    Hope this helps,


  • Sorry, I was referring to the max size for comments on this blog.

  • I've succeeded in rewriting 404 requests from IIS back to their original url in ASP.NET, but IIS 5.1 doesn't allow post-backs to unmapped extensions.

    Does IIS6 allow the POST verb to unmapped extensions?

    How bad is the performance hit when IIS is configured to send * to the runtime?


  • I just read that ASP.NET 2.0 is now capable of sending requests back to IIS for proccessing, so mapping * to aspnet_isapi.dll doesn't invoke a performance hit.

    I originally read something (probably regarding 1.1), that stated how deadly it was to map * to aspnet_isapi.dll, due to performance issues.

    Is this correct? I've tried to do URL mapping in various ways without this, and failed miserably. I have tried leveraging the 404 rewrite in IIS, using a mixed rewrite/redirection system, and many other less successful approaches.


  • Hi Nathanael,

    You can now enable * mapping much more efficiently using IIS6. For static files (like .htm and .asp), ASP.NET will then call back into IIS to have it process them.

    Can you send me an email regarding url rewriting? I can then loop you in with someone to help.



  • Ok, I have another problem...

    I am caching ASP.NET snippets in the database for the summary field on each article.

    As the paths in each snippet are relative to the parent article file, I have been creating an instance of Page and using the ParseControl method. Unfortunately, this seems to simply bring back a LiteralControl instead of the proper hierarchy.

    What do you reccomend?

  • Addendum: I mean AppRelativeTemplateSourceDirectory, not TemplateSourceDirectory. Also, this property must be set recursively. See example below.

    /// Recursively sets the AppRelativeTemplateSourceDirectory property on the specified control and all of its children


    public static void SetPathRecursive(Control c, string AppRelativeTemplateSourceDirectory) {
    if (c == null) return;
    c.AppRelativeTemplateSourceDirectory = AppRelativeTemplateSourceDirectory;
    foreach (Control child in c.Controls) {
    SetPathRecursive(child, AppRelativeTemplateSourceDirectory);

    /// Renders the specified code to the specified output stream
    /// The code to render


    /// The parent page

    /// The path the specified code should be virtually executed from. The location relative paths are resolved from

    public static void RenderCode(string code, TextWriter output, Page parent, string AppRelativeTemplateSourceDirectory) {

    //Parse the text into a control object (a container control object is created automatically.
    Control c = parent.ParseControl(code);
    SetPathRecursive(c, AppRelativeTemplateSourceDirectory);
    //Render to the control
    XhtmlTextWriter htw = new XhtmlTextWriter(output);


  • Hi Yenkay,

    Developing an offline application using ASP.NET is pretty hard (since it needs to be connected to a web-server).

    I'd probably recommend building a Windows Forms or WPF client application instead. This will enable you to work disconnected from a web-server.

    Hope this helps,


  • Scott,

    Do you have any links to information on the process of developing an ASP.NET web application using Team Foundation Server? If not, I'd love to see some posts from you along those lines or some howto videos/articles on the subject.

    Interested in having my small team of developers (3) able to checkout files, update them, test/debug their changes to the site locally on the machine and then when they check in the files, only then would the changes be reflected on the development IIS server.

    Thanks in advance for any help/links you can provide.


  • Hi Tom,

    I don't know of some off the top of my head, but Brian Harry has a great blog here and might be able to help:

    He runs the TFS team and blogs a lot about it.



  • On Aug 8 there was a post that stated, "I have worked around this by handling the objectdataSource Updating event and adding the values into the object manually..." Can you show an example of how to get at the object that is created?

    For example, I have the below and before that update method is called I need to set a property on that Employee object that is passed to Update.


    protected void objectsource_Updating(object sender, ObjectDataSourceMethodEventArgs e)

    [DataObjectMethod(DataObjectMethodType.Update, true)]
    public static bool Update(Employee o)
    return true;

  • Hi Shawn,

    I believe you can add the values using the "e" parameter to the updating event above. I believe there is a Params collection there where you can add any custom values you want.

    Hope this helps,


  • do you have tips for VS 2005 and database express?

Comments have been disabled for this content.