开发者

"The DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl." error in asp.net

I have a Login control placed inside LoginView control contained within a PANEL. I want to set login button as the default button for this panel. It is not possible in design view to set the default button. So i am trying to set it usin开发者_JAVA百科g 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 am getting both the controls i.e. Panel and Button but the code generates the following error message -

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

I have also tried using UniqueID instead of ClientID but still the same problem.

Can anyone help me out, how this error can be rectified? Thanks for sharing your time.


I know you've said that you tried ClientID and UniqueID, however I used UniqueID and it worked for me.


If you move the panel inside the login's template:-

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

Then it will work without code. You can set loginbuttontype="Image" or Link or button according to your requirement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜