views:

11

answers:

0

Hello friends, 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 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 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.

Regards

Irfan