defaultbutton Property with Master Page

Last post 05-11-2007 2:13 AM by Amanda Wang - MSFT. 1 replies.

Sort Posts:

  • defaultbutton Property with Master Page

    05-09-2007, 10:42 AM
    • Member
      250 point Member
    • JayMan
    • Member since 07-04-2005, 10:10 PM
    • Posts 100

    Hello everyone,

    I have a master page that handles login for my users.  I would my users to be able to enter their user name and password, and then hit enter to login rather than just clicking the login button.  So I have placed my login controls in a panel control and set the defaultbutton property to the ID of the login button.  Now, when I run my app, I get this error:

    The DefaultButton of 'LoginPanel' must be the ID of a control of type IButtonControl.

    Is there something I am missing here? 

    My code is as follows:

    <

    asp:Panel runat="server" ID="LoginPanel" defaultbutton="LoginButton2">

    <asp:LoginView ID="lv1" runat="server">

    <AnonymousTemplate>

    <asp:Login ID="Login1" runat="server">

    <LayoutTemplate>

    <h3 class="none">

    Log into ACRDC Site

    </h3>

    <fieldset>

    <legend class="none">Log into ACRDC Site</legend>

    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User name:</asp:Label>

    <br />

    <asp:TextBox ID="UserName" runat="server" Width="112px"></asp:TextBox>

    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"

    ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="Login1" ForeColor="White">*This field is required</asp:RequiredFieldValidator>

    <br />

    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>

    <br />

    <asp:TextBox ID="Password" runat="server" TextMode="Password" Width="112px"></asp:TextBox>

    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"

    ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1" ForeColor="White">* This field is required</asp:RequiredFieldValidator>

    <br />

    <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />

    <p>

    </p>

     

    <asp:ImageButton ID="LoginButton" runat="server" commandname="Login" ValidationGroup="Login1" ImageUrl="images/LoginButton.gif" />

    <br />

    <asp:Button ID="LoginButton2" runat="server" commandname="Login" ValidationGroup="Login1" Visible="true" />

     

    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>

    </fieldset>

    </LayoutTemplate>

    </asp:Login>

    Fogot you password?

    <br />

    <asp:HyperLink ID="HyperLink1" runat="server" ForeColor="Blue" NavigateUrl="~/Login.aspx">Click Here</asp:HyperLink>

    </AnonymousTemplate>

    <LoggedInTemplate>

    You are logged in!

    <h3>

    Hello

    <asp:LoginName ID="LoginName1" runat="server" />

    </h3>

    <p>

    Welcome back to the ACRDC website.

    </p>

    </LoggedInTemplate>

    </asp:LoginView>

    </asp:Panel>

    Any help would be greatly appreciated.

    Thanks

    JayMan
  • Re: defaultbutton Property with Master Page

    05-11-2007, 2:13 AM
    Answer

    Hi,

    In the masterpage,

    LoginButton2 looks good at first, but if you search for it in the code, you won't find a control with an Id of LoginButton2. You do, however, find this:

    <input type="submit" name="Login1$LoginButton2" value="Log In" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;Login1$LoginButton&quot;, &quot;&quot;, true, &quot;Login1&quot;, &quot;&quot;, false, false))" id="Login1_LoginButton2" />

    Because the page is based on a Master Page, the HTML name and id attributes have been prefixed with the names of their naming container, the ContentPlaceHolder1 in this case. 

    you also could write in the code behind: this.Panel1.DefaultButton = this.Login1.FindControl("LoginButton").UniqueID;

    The more information please click following link:  http://www.spaanjaars.com/QuickDocId.aspx?QUICKDOC=374

     

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (2 items)