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

UI

AJAX 

Data

Security

Deployment

Performance

.NET 3.5 and VS 2008

LINQ and .NET 3.5

Silverlight

Miscellaneous

Published Monday, July 31, 2006 11:00 PM by ScottGu

Comments

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, August 2, 2006 5:21 PM by Sue Googe
This is awesome! It save us time digging around your blog :-) Keep up with the good work!

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, August 2, 2006 5:56 PM by 压力变送器
Nice post.. I have only just come across your blog and what I have read so fair has been very helpful.

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Thursday, August 3, 2006 12:04 PM by knave
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!

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Friday, August 4, 2006 11:59 AM by Willie L.
Scott, Terrific...It's an awesome list and very helpful references. You're great! Thanks a lot.

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Monday, August 7, 2006 10:01 AM by Daniel
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. Cheers dan.

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Tuesday, August 8, 2006 12:51 AM by ScottGu

Hi Daniel,

For tutorials on 2 way databinding, I'd recommend checking out this tutorial series: http://weblogs.asp.net/scottgu/archive/2006/06/22/454436.aspx  as well as the quickstart samples on data: http://www.asp.net/quickstart

Hope this helps,

Scott

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Tuesday, August 8, 2006 6:45 AM by Daniel
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? cheers dan.

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Friday, August 11, 2006 2:52 AM by ScottGu

Hi Dan,

You can do 1 way evaluation of complex objects using the <%# Eval() %> syntax:

<%# Eval("Person.Address.Postcode") %>

Unfortunately two-way binding of sub-properties via the <%# Bind %> 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,

Scott

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, August 30, 2006 12:06 PM by chris
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?

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Thursday, August 31, 2006 1:49 AM by ScottGu

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,

Scott

# Data Source Control vs. Simple Data Coding

Saturday, September 16, 2006 6:19 PM by JaiPrakash
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...........

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Sunday, September 17, 2006 2:18 AM by JaiPrakash
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???????

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Tuesday, September 19, 2006 12:12 AM by ScottGu

Hi Jai,

Atlas Control Extenders are fully supported with hosting scenarios.

Hope this helps,

Scott

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Tuesday, September 19, 2006 12:13 AM by ScottGu

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,

Scott

# Mulitple Website and Single Sign in

Saturday, September 23, 2006 10:24 AM by JaiPrakash
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 site1.com(say), than he or she should be able to sign in for site2.com and site3.com. hence, if user has sign up for the membership of site1.com than he/she should automicallly become the member of site2.com and site3.com. and also if the member sign in for the site1.com and if opens sign2.com or site3.com 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.........

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Sunday, September 24, 2006 11:57 AM by ScottGu

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:

http://www.microsoft.com/technet/security/topics/identitymanagement/idmanage/default.mspx?mfr=true

http://www.wwwcoder.com/main/parentid/258/site/4922/68/default.aspx

Hope this helps,

Scott

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, October 25, 2006 8:41 AM by Prabakar Samiyappan
Its Nice and very Intresting to read all the Articles.its a good link which is to added in favorites...

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Thursday, November 9, 2006 10:42 AM by Irfan
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. Thanks, Irfan

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, November 22, 2006 4:05 AM by philemon wachara

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.

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, November 29, 2006 2:18 AM by Ekambaram

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

# Resizing a web page

Thursday, December 7, 2006 1:05 PM by Ray Levron

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?

regards,

Ray Levron

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Thursday, December 7, 2006 11:40 PM by ScottGu

Hi Ray,

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

Sorry!

Scott

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Thursday, December 28, 2006 2:53 PM by raymondo

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 asp.net 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 asp.net 2.0

thanks

raymondo

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Monday, January 8, 2007 3:59 PM by Erick

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...

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Friday, January 19, 2007 12:39 AM by ARC

Hi Scott. Your blog is a great asp.net resource and as i am new to asp.net, 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 asp.net allow master pages to load resources from subfolders even with anonymous user?

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Friday, January 19, 2007 9:04 PM by ScottGu

Hi ARC,

I believe this blog post will fix your problem: http://weblogs.asp.net/scottgu/archive/2006/01/31/437027.aspx

Hope this helps,

Scott

# Posting Issues

Wednesday, January 24, 2007 11:10 AM by Nathanael Jones

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.

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, January 24, 2007 11:53 AM by ScottGu

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 <httpRuntime> section within your web.config file.

Hope this helps,

Scott

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, January 24, 2007 1:34 PM by Nathanael Jones

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

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Thursday, January 25, 2007 8:25 AM by Nathanael Jones

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?

Thanks,

Nathanael

# URL Rewriting

Thursday, January 25, 2007 9:21 AM by Nathanael Jones

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.

Thansk,

Nathanael

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Tuesday, January 30, 2007 12:36 AM by ScottGu

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.

Thanks,

Scott

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Tuesday, January 30, 2007 1:49 PM by Nathanael Jones

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?

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, January 31, 2007 8:36 AM by Nathanael Jones

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

========================

/// <summary>

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

/// </summary>

/// <param name="c"></param>

/// <param name="AppRelativeTemplateSourceDirectory"></param>

public static void SetPathRecursive(Control c, string AppRelativeTemplateSourceDirectory) {

   if (c == null) return;

   c.AppRelativeTemplateSourceDirectory = AppRelativeTemplateSourceDirectory;

   foreach (Control child in c.Controls) {

       SetPathRecursive(child, AppRelativeTemplateSourceDirectory);

   }

}

/// <summary>

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

/// </summary>

/// <param name="code">The code to render</param>

/// <param name="output"></param>

/// <param name="parent">The parent page</param>

/// <param name="VirtualPath">The path the specified code should be virtually executed from. The location relative paths are resolved from</param>

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);

   c.RenderControl(htw);

}

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Tuesday, February 27, 2007 2:24 AM by ScottGu

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

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Saturday, March 3, 2007 12:27 PM by Tom

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.

-Tom

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Saturday, March 3, 2007 9:15 PM by ScottGu

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: http://blogs.msdn.com/bharry

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

Thanks,

Scott

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Wednesday, March 7, 2007 6:19 PM by Shawn Palmer

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.

.aspx

dataobjecttypename="mynamespace.Employee"

updatemethod="Update"

.aspx.cs

protected void objectsource_Updating(object sender, ObjectDataSourceMethodEventArgs e)

{

   ...

}

Employee.cs

[DataObjectMethod(DataObjectMethodType.Update, true)]

public static bool Update(Employee o)

{

   o.Save();

   return true;

}

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Thursday, March 8, 2007 4:57 PM by ScottGu

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,

Scott

# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

Thursday, March 15, 2007 9:32 AM by Very useful post

do you have tips for VS 2005 and database express?