Monday, May 21, 2007

asp:Login... .net 2.0 login control and Default page button

How to make Login button of control default on enter button
If your login control is defined like this:

asp:Login ID="LoginCtrl" runat="server" />


add this code to Page_Load handler


protected void Page_Load(object sender, EventArgs e)
{
Button btn = (Button)LoginCtrl.FindControl("LoginButton");
if (btn != null)
Page.Form.DefaultButton = btn.UniqueID;
}


Note: This works only if LoginButtonType is Button, if not this does not work

No comments: