ASP.NET 2.0 Login control

G

Guest

Does anybody know a way to make the button on the Login control be the
default button on the page? I have a master page with an ImageButton and a
content page with a Login control. When I enter the id and password and
press the Enter key, the ImageButton (on the master page) fires instead of
the Login button of the Login control on the content page. The Login
composite control does not appear to expose a reference to its button.

Thanks in advance
 
G

Guest

The problem is that to set a button as the default button, it must implement
the IButtonControl interface. The Login control does not implement the
IButtonControl interface and the button inside the Login control is not
exposed. I tried Form.DefaultButton = "Login1" and it will not compile. Your
solution would require something like: Panel1.DefaultButton = "Login1"
(correct me if I am wrong).

Certainly Microsoft has thought this through??
 
D

David Barkol

You're right. In this case you are going to have to use your own
controls and leverage the Membership API's to validate the login.
 
G

Guest

David,

Thanks for your interest. I chose to workaround it by disabling the
ImageButton (on the master page) during the Login process. Works fine but
its technically a kluge.

Have a great weekend,

Glen
 
S

simonjarita

hi glen,

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;
}
}

i got this information searching the msdn asp.net documentation and it
works fine. however there's one problem still:

when the login control is configured to "refresh" itself on the client
side without reloading the page from the server if the validation
failed (e.g. no password entered) then it will reset the default button
(makes absolutely no sense to me!)

hope this helps. let me know if find out something about the refresh
issue.

simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top