Far Away Developer

Sebastien Lachance

Archive for the 'ASP.NET' Category

ASP.NET

New code drop to the ASP.NET project on Codeplex

Posted by Sebastien Lachance on May 13, 2008

  • 05/12 Source code release of the ASP.NET AJAX Script Profiler helper control: To support the ASP.NET AJAX script combining feature which shipped in the .NET Framework 3.5 SP1 Beta release, we’ve added the ASP.NET AJAX Script Profiler helper control source and binaries to this project. This control helps you to identify the scriptreferences used in your ASP.NET AJAX page to use with ASP.NET AJAX script combining. You can find this release here: ScriptReferenceProfiler Source and Binary Release. In addition this control is used in a Screencast for ASP.NET AJAX script combining on the ASP.NET site.
  • 05/12 Release of the ADO Data Service AJAX Client : The ADO Data Service AJAX Client Library enables you to consume an ADO.NET Data Service from client script in an ASP.NET AJAX Web page.

Read more here.

I am really wondering how I can keep up with all these new things to try. Well, I guess we will really need a pill to stop sleeping one day.

Posted in .NET, ASP.NET | 1 Comment »

Cannot have multiple items selected in a DropDownList.

Posted by Sebastien Lachance on March 8, 2008

Cannot have multiple items selected in a DropDownList.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.
Source Error:

Line 253:            total = parseFloat(lblTotal.innerHTML.replace('$', '').replace(',', '.'));
Line 254:            fBudget = parseFloat(budget.replace('$', '').replace(',', '.'));
Line 255:            var lblWarningContract = document.getElementById('<%= lblWarningContract.ClientID %>');
Line 256:
Line 257:            if (total > fBudget)

I spent at least one hour figuring this out. The Source Error  does not contain any valid information. The solution is : you should never use the same item twice on two different dropdownlist.

ListItem item = new ListItem(" -- Select one -- ", "-1");

ddlLoadingContact.Items.Insert(0, item);
ddlUnloadingContact.Items.Insert(0, item);

A ListItem have a property called Selected that tells which one (the item) the dropdownlist should display as selected. If you use the same ListItem in more that one dropdownlist and you select this item in the DropDownA and a different item in DropDownB. The DropDownB will have two ListItem with the Selected property set to true. Since this is the same item in both dropdownlist.

ddlLoadingContact.SelectedValue = "-1"; //item will have the Selected property set to true
ddlUnloadingContact.SelectedValue = "John";  //another item will have the Selected property set to true. And both are contained in this dropdownlist.
 
 

Posted in .NET, ASP.NET | 4 Comments »

Screencast goodness

Posted by Sebastien Lachance on December 24, 2007

Here is the bests screencasts I have watched this week :

Monorail Quickly: A screencast made by Joey Beninghove (joeyDotNet). I have quite enjoyed this one. He has done a template project for quickly starting up a solution for Monorail.

A series of screencasts from colinramsay.co.uk :

A ton of new screencasts about ASP.NET 3.5 Extensions.

And I wish you a merry Christmas!

Posted in .NET, ASP.NET, Fun, Learning, Visual Studio | No Comments »

ASP.NET Identity Matrix

Posted by Sebastien Lachance on June 21, 2007

This can be of great help for all of you who deploy ASP.NET applications or Web Services. Countless hours have been lost forever. But no more!

ASP.NET Identity Matrix

Posted in .NET, ASP.NET | No Comments »

CommandField and ButtonType="Image"

Posted by Sebastien Lachance on December 1, 2006

My first real bug with the framework and a good one. It appears that if you have a CommandField in a GridView with the ButtonType set to Image with an ImageUrl for the button you want, the event (OnRowDeleting, OnRowEditing, etc..) will be fired twice. But the DataSource could play some part in it. By example, if you have an SqlDataSource, it will not happen. In my case, it was a list of object bound in the codebehind.

The way I found to resolve this issue was to create a TemplateField and add an ImageButton with a CommandName of “Delete”. This way the OnRowDeleting will be fired (for a list of other command name, just fire the OnRowCommand event and check what the GridViewCommandEventArgs.CommandName). I’m still trying to find an official response from the .NET team to confirm all this, but the community think it’s a bug.

If you do not want to create a TemplateField for this, there is an alternate solution. You can use this in you event :

if (Request["x"] == null || Request["y"] == null)
{
Response.End();
}

Posted in .NET, ASP.NET | No Comments »

‘Sys’ is undefined

Posted by Sebastien Lachance on November 25, 2006

Lastly I have got to play a lot with AJAX (ATLAS) and have been pleasantly surprised by the quality and the ease of use of the product. Really easy to use and “a lot of support” for it. For every problem there is a solution and those seem to be resolved fast by the community.

The first really big error so far, is the ‘Sys’ is undefined one. There seems to have a problem with the anonymous user being disable for the web site (in particular the script folder). Well, i’m sure that I wont allow anonymous users to access critical data, so adding a new location in the Web.Config for this specific folder with solve the problem.

Here is the lines to add :

<location path=”ScriptResource.axd”>
<system.web>
<authorization>
<allow users=”*”/>
</authorization>
</system.web>
</location>

There can be also the fact that the resource handler is not set, so adding the following line in the Web.Config, should also solve the problem :

<add verb=”GET” path=”ScriptResource.axd” type=”Microsoft.Web.Handlers.ScriptResourceHandler” validate=”false”/>

Posted in .NET, ASP.NET | No Comments »

ListControl.SelectedValue

Posted by Sebastien Lachance on October 12, 2006

Every time I set the SelectedValue of a DropdownList in ASP.NET, I was checking if the value existed in the control and if it doesn’t, I usually set a default one (creating a new item with a SelectedIndex of -1). I realized that if you set the FormattingEnabled to true, the SelectedIndex will be set to -1. Thus removing the need for the this check.

This property is found on the ListControl class, with the Dropdownlist inherit.

Happy coding !

Posted in .NET, ASP.NET | No Comments »