"DefaultButton from" Panel1 "must be the identifier of the IButtonControl control." Error in asp.net

I have a Login control located inside a LoginView control contained in a PANEL. I want to set the login button as the default button for this panel. It is not possible to set a default button in a design. Therefore, I am trying to install it using code.

Below is the code:

protected void SetDefaultButtonForLoginControl()
{
    Login loginCtrl =  (Login)LoginView1.FindControl("Login1");
    Panel panel1 = (Panel)LoginView1.FindControl("Panel1");

    if (loginCtrl != null)
    {
        Button btn = (Button)loginCtrl.FindControl("btnLogin");
        if (btn != null)
        {
            panel1.DefaultButton = btn.ClientID;
        }
    }
}

I get both controls, i.e. panel and button, but the code generates the following error message -

DefaultButton 'Panel1' must be the identifier of the IButtonControl control.

I also tried using UniqueID instead of ClientID, but still the same question.

- , ? , .

+3
2

, , ClientID UniqueID, UniqueID, .

+1

: -

<asp:login id="Login2" runat="server" loginbuttontype="Image">
<layouttemplate>
<asp:`enter code here`panel id="Panel1"   runat="\
 server"defaultbutton="LoginImageButton">
</asp:Panel>

. loginbuttontype = "" .

0

Source: https://habr.com/ru/post/1752045/


All Articles