Your Ad Here Visit new version of this Blog

i had the same problem (login control in page and imagebutton in
masterpage).

the whole asp.net page is usually a form so you have to set the default
button for that main form.

in the Page_Load function of your web page get a reference to the main
form ("form1") which is in master page:

HtmlForm mainform = (HtmlForm)Master.FindControl("form1");

then get a reference to your login button in the login control (convert
your login control in a editable template and you'll see the ID of the
button, however this ID is not directly accessable yet, you have to
search for it with FindControl):

Button loginbtn = (Button)myLoginControl.FindControl("LoginButton");

your main form then wants a unique ID of the default button:

mainform.DefaultButton = loginbtn.UniqueID;

here's the complete code:

protected void Page_Load(object sender, EventArgs e)
{
myLoginControl.Focus();
HtmlForm mainform = (HtmlForm)Master.FindControl("form1");
Button loginbtn =
(Button)myLoginControl.FindControl("LoginButton");
if (mainform != null && loginbtn != null)
{
mainform.DefaultButton = loginbtn.UniqueID;
}
}

0 comments: