Ryan Ternier

Killer ASP.NET ninja coding monkeys do exist!

Master Pages, buttons, Login Control, and the default button

I've been working on a MasterPage that has a search box and search button.

When the master page loads in the Login page, the default button is set to the search button. This is not good when a user wants to press "Enter" on the username/password textbox.

I tried to do this:

<asp:Panel ID="pnlLogin" runat="server" DefaultButton="LoginButton">

    <asp:Login ID="lgnSecurity" OnAuthenticate="lgnSecurity_Authenticate" runat="server" />

</asp:Panel>

However, that didn't work and I got parser errors. I was playing and finally came up with this, which works perfectly.

lgnSecurity.Focus();
((HtmlForm)Master.FindControl("MainForm")).DefaultButton = ((Button)lgnSecurity.FindControl("LoginButton")).UniqueID;



Posted: Aug 14 2007, 02:19 PM by Ryan Ternier | with 4 comment(s)
Filed under: , ,

Comments

Neeraj Mude said:

Thanks dear , it helps me lot

# October 17, 2007 4:22 AM

Tz said:

The problem is with the Panel.DefaultButton that the panel calls FindControl on itself, and not on your login control as you do in your workaround.

Not sure how much of a hack, but the FindControl uses $ or : as path separator to "look deeper" in the control tree, so for me it works fine with the following DefaultButton string:

<asp:Panel ID="pnlLogin" runat="server" DefaultButton="lgnSecurity$LoginButton">

   <asp:Login ID="lgnSecurity" OnAuthenticate="lgnSecurity_Authenticate" runat="server" />

</asp:Panel>

# November 14, 2007 3:12 AM

Helen said:

Thanks!  It save me a lot of trouble to figure it out.

# December 11, 2007 6:31 PM

Leo said:

Thank you Tz!

# September 12, 2008 4:30 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)