Thread: ASP.NET/Using Panel.DefaultButton property with LinkButton control in ASP.NET

Using Panel.DefaultButton property with LinkButton control in ASP.NET

kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/





Re: Using Panel.DefaultButton property with LinkButton control in ASP.NET

The default button on enter on an ASP.NET form


weblogs.asp.net/jeff/archive/2005/07/26/420618.aspx





Re: Using Panel.DefaultButton property with LinkButton control in ASP.NET

Completely remove "Enter button behaviour":


<form ... onsubmit="return false">





Re: Using Panel.DefaultButton property with LinkButton control in ASP.NET

In master page create style:



<


style type="text/css">

 


.hiddenbutton

{


 


}


display:none;

</


style>

 



Add button the first line after Form tag:



 


 



<


asp:Button ID="btnFakeDefault" CssClass="hiddenbutton" Enabled="false" runat="server" OnClientClick="return false;" />

 


 


In code behind for the event OnInit add explicit assignment for our button:



form1.DefaultButton = btnFakeDefault.UniqueID;



That is it! We disabled our default button without postback.


 



 


 


 





Re: Using Panel.DefaultButton property with LinkButton control in ASP.NET

Assign your button as default (add this line of code into your page event Load):


Page.RegisterHiddenField("__EVENTTARGET", "btnSearch")


where "btnSearch" should be name of your button...