Link to home
Start Free TrialLog in
Avatar of tony_trotter
tony_trotterFlag for United States of America

asked on

Problem Accessing the Button within the Login Control LayOutTemplate

I'm sure there is probably an easy sanswer to this but I'm tired of working on it.  Maybe someone out there has a quick answer to this.

I have a login control that exists within a panel.  I have converted the Login control to a template and would like to set the LoginButton of the Login control to be the DefaultButton of the panel.  Simple  . . . .Right?  Wrong.  I can't seem to make the code find the LoginButton.  Here is the code I tried to use.  What did I do wrong?

        Dim btnLoginButton As New Button
        btnLoginButton = Me.loginbox.FindControl("LoginButton")
        pnlBackground.DefaultButton = "btnLoginButton"

Thanks in Advance.

Tony
Avatar of Elvio Lujan
Elvio Lujan
Flag of Argentina image

you can use the general default button:

            public void DefaultButton(System.Web.UI.WebControls.TextBox objTextControl, System.Web.UI.WebControls.Button objDefaultButton)
            {
                  //Sets default buttons.
                  System.Text.StringBuilder sScript = new System.Text.StringBuilder();
                  sScript.Append("<SCRIPT language=\"javascript\">\n");
                  sScript.Append("function fnTrapKD(btn){\n");
                  sScript.Append(" if (document.all){\n");
                  sScript.Append("   if (event.keyCode == 13)\n");
                  sScript.Append("   { \n");
                  sScript.Append("     event.returnValue=false;\n");
                  sScript.Append("     event.cancel = true;\n");
                  sScript.Append("     btn.click();\n");
                  sScript.Append("   } \n");
                  sScript.Append(" } \n");
                  sScript.Append("}\n");
                  sScript.Append("</SCRIPT>\n");
                  objTextControl.Attributes.Add("onkeydown", "fnTrapKD(document.all." + objDefaultButton.ClientID + ")");
                  this.Page.RegisterStartupScript("ForceDefaultToScript", sScript.ToString());
            }
Avatar of tony_trotter

ASKER

Thanks but I'm not sure if this will work for me because the page has a couple other "DefaultButtons".  That's why I have the control in a panel, because I want the defaultbutton to be focus sensitive. On this website my "Search" feature is already (and needs to be) the Default page button.

Thank you very much though!

I'm hoping for insight into how to access THAT LoginButton in THAT Login control.  Surely, there is a way to do it.  Isn't there?

OH!

I guess it would be helpful to let everyone know the error that I get when I use the code in my original message.  It is:

"The DefaultButton of 'pnlBackground' must be the ID of a control of type IButtonControl."
Avatar of idealsw
idealsw

I have exactly the same issue, have you managed to sort it out yet?
Thanks.
No not yet.  Still hopeful.  I'm sure someone will eventually see this and have an answer.  (I hope)
I'm increasing the reward on this question.  Can anyone help us out here??
ASKER CERTIFIED SOLUTION
Avatar of idealsw
idealsw

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked Beautifully!!!!!!

I knew it had to be a simple solution.  I just couldn't see it.

Thank you SO much!!!


For anyone else who has had this problem, the following code made the "Enter Key" kick off my button_click event on my Login control when it had focus but still allowed the page default button to work when the login control DID NOT have focus.

    Protected Sub loginbox_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles loginbox.Load
        Page.Form.DefaultButton = CType(loginbox.FindControl("LoginButton"), Button).UniqueID
    End Sub