ASP.NET tab is missing from IIS 6.0

Problem Description

We all know this problem, the ASP.NET tab is missing from the IIS 6.0 website properties and you know, that you have more than one version of ASP.NET installed. Great, what do you do?

Solution

Doing a manual check on the configuration can be a very difficult task, since you will have to check a lot of different settings. The ASP.NET Debugging blog have posted a script that will check your configuration settings for you, and better yet, it will fix any problems you might have. I have tested this on my server, and the ASP.NET tab re-appeared immidiatly.

http://blogs.msdn.com/b/tom/archive/2008/04/17/asp-net-tab-missing.aspx

Also note that when installing ASP.NET you must use the command:

aspnet_regiis.exe -ir -enable

This will install ASP.NET and enable it for use, but it will not upgrade or touch existing ASP.NET sites. In order to make the existing sites work with ASP.NET you must select the desired ASP.NET version from your newly recovered ASP.NET tab in the website properties dialog.

Happy programming!

ASP.NET DataSet: Remember the length of parameters

Problem:

You have just changed the size of a varchar column (perhaps a size 20 to a size 50) in your database. You have then manually updated your data set to use the new size, but your data set does not save values with the new size. It keeps cutting off text.

Solution:

You have forgot to set the size of the parameter in your customized query.

  • Select the query in on the table adapter.
  • Right click and select properties.
  • Expand the Parameters property and change the size of your column.

Now your problem is solved!

Happy programming!

How to make ASP.NET GridView use thead and tbody elements.

Problem:

You have an ASP.NET 2.0 GridView and would like to use printed media, but the GridView does not use <tbody> and <thead> elements, so you cannot print the header on each page.

Solution:

You make the GridView use <tbody> and <thead> elements by changing some properties. Like creating a method like the one below:



/// <summary>
/// Make the GridView use the thead and tbody elements.
/// </summary>
/// <param name="grid">The gridview in question.</param>
private void MakeGridViewPrinterFriendly(GridView gridView) {
    if (gridView.Rows.Count > 0) {        
        gridView.UseAccessibleHeader = true;
        gridView.HeaderRow.TableSection = TableRowSection.TableHeader;
    }
}


You can do the same thing with the FooterRow. I suggest you add this method to your web development framework.

To have IE print the table-header on each page you need to add the "display:table-header-group" to the <thead> element. The easiest way to do this is to wrap the table in a <div> element and associate it with a CSS class. Then you need to create a special case for the thead-elements used inside a div associated with that class:



.MyCssClass thead {
    display: table-header-group;
}


Use it like this:

<div class="MyCssClass">
    <table>
        <thead>
            ....


This post is based on information from this article: http://www.webpronews.com/expertarticles/2007/01/25/aspnet-make-gridview-control-accessible

Happy programming!

Must declare scalar value

Problem:

You have made a change to an insert method of an ASP.NET dataset, by adding one or more input parameters, and you've noticed that it has not updated the actual method in the generated code. When running the insert method you get the following error: "Must declare scalar value ..."

Solution:

One thing causing this could be that you have added "SELECT SCOPE_IDENTITY()" to the end of the SQL in the data set method. This will prevent the data set code generator from updating the method in the generated code even though it tells you the method has been updated.  Remove "SELECT SCOPE_IDENTITY()" from the SQL and add the variable. Update the dataset, compile the code and put the "SELECT SCOPE_IDENTITY()" back in. Remember to change the ExecuteMode property of the method back to Scalar!

Your problem is now solved.

Happy programming! :-)

Server Application Unavailable

If you receive the following, you should check the event log of your server to solve the issue. I once received this because the service account running the website did not have correct access rights. http://msdn.microsoft.com/en-us/library/kwzs111e.aspx

Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.

Happy Programming!

How to find a control in an ItemTemplate on the ASP.NET Repeater control.

This problem seems to be occurring every once in a while on forums troughout the internet. This post will show you what to do.

The problem:

You would like to access a control in the item template on your ASP.NET repeater control, but every attempt to use "FindControl" on the repeater fails with the return of a null value. 

The solution:

You are using the wrong "FindControl" the solution is to use the repeater's "OnItemDataBound" event. This will give you access to the current repeater item using the event arguments. Like this:



/// <summary>
 /// Binds a navigate url to the hyperlink in the template.
 /// </summary>
 protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e) {
     HyperLink hyperLink = (HyperLink)e.Item.FindControl("headerHyperLink");
      hyperLink.NavigateUrl = CreateHyperlink((CalendarItem)e.Item.DataItem);
}


The trick is to use the "Item" property of the event argument. This is actually the template and using the FindControl on the "Item" property will give you the result you want.

Happy programming! :-)