DefaultButton property of panel in ASP.Net


ASP.NET allows only one server form on the page. Even if you are developing complex page, which looks like several forms with different submit buttons, in fact you have only one form. There we will get a problem: How browser understanding which button should be triggered when user presses ENTER?  Generally it triggers first Button control in the form.

In ASP.NET 2.0 new property has been added to the Panel and HtmlForm controls - DefaultButton property, which can be used to specify ID of the control, which implements IButtonControl interface. This button control would be triggered when user pressed ENTER.

The DefaultButton property is used to set or return the id of the default button for the Panel or Form control.

The DefaultButton can be set to the identifier, for a Button control or any control that implements the IButtonControl interface, except a LinkButton control.

If the DefaultButton is set to a control that does not implement the IButtonControl interface, or to a control that is not contained in the Panel control, the Panel control throws InvalidOperationException while rendering.

Example:

< asp : Panel ID ="Panel1" runat ="server" DefaultButton ="btnSubmit">

 
   <!--
        Some data
    -->

    <
asp:Button ID="btnSubmit" runat="server" Text="Submit" />

</
asp:Panel>

Mr. Praveen N. Mulukutla - Software Engineer
I like to write articles on Programming languages. The idea of articles come from my own experiences while working in those areas and i like to share my knowledge on POP3 services with all others so that it might be helpful.
Service is my Motto & Knowledge is Divine
http://www.mulukutlas.blogspot.com
Read moreRead more about Contributor