Labels

Wednesday, June 20, 2007

Default buttons in ASP.NET 2.0 for each Panel

It’s a normal scenario in the web application that the page contains different panels and each panel may contain default buttons.

How to set the default button for a Panel in ASP .NET 2.0

All we need to do is to set the DefaultButton property of the panel with the Target Button ID.

Ex:

<asp:Panel ID="panelDefault" runat="server" DefaultButton=" buttonSample ">

<asp:TextBox ID="textBoxSample" runat="server"></asp:TextBox>

<asp:Button id="buttonSample" runat="server" Text="Sample"/>

</asp:Panel>    

 

Above code will work fine in IE. But will through “Permission denied to set property ULElement.SelecteIndex…” exception in case of Firefox.

 

To solve this problem we need set the property UseSubmitBehavior="false" of the default button. UseSubmitBehavior property gets or sets a value indicating whether the Button control uses the client browsers submit mechanism or the ASP.NET postback mechanism. If we set this value to “false” then the ASP.NET page framework adds client-side script to the page to post the form to the server. Else browsers submit mechanism is used to submit the page.

 

True - ASP.NET postback

False - Client Browsers Submit

 

The modified code:

<asp:Panel ID="panelDefault" runat="server" DefaultButton=" buttonSample ">

<asp:TextBox ID="textBoxSample" runat="server"></asp:TextBox>

<asp:Button id="buttonSample" runat="server" Text="Sample" UseSubmitBehavior="false" />

</asp:Panel>

 

Above code will work in both  IE and Firefox.

For details on UseSubmitBehavior property visit the following site:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx

 

 

Thanks & Regards,

Arun Manglick

SMTS || Microsoft Technology Practice || Bridgestone - Tyre Link || Persistent Systems || 3023-6258

 

DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.

No comments:

Post a Comment