I have an ASP.NET web page with a Login control on it. When I hit Enter, the Login button doesn't fire; instead the page submits, doing nothing.
The standard solution to this that I've found online is to enclose the Login control in a Panel, then set the Panel default button. But apparently that doesn't work so well if the page has a master page. I've tried setting the default button in code with control.ID, control.ClientID, and control.UniqueID, and in each case I get:
The DefaultButton of panelName must be the ID of a control of type IButtonControl.
I'm sure there's a way to do this with JavaScript, but I'd really like to do it with plain old C# code if possible. Is it possible?
Yo, i found this solution on the net, it worked for me.
To add a bit more detail and instructions to the posts above, here's a walkthrough:
In the markup of any pages that load your login control, you need to update the html in two places.
First, in the page's form tag, you need to set the default button. See below for how I came up with the name.
(Naming: The ucLogin part before the dollar sign needs to be the ID of your login control, as declared further down in your page. The btnSubmit part needs to be the ID of the button as it’s named in the login control’s html)
Next, you need to wrap the declaration of your login control in a panel, and set it’s DefaultButton property, as well:
That should do it for you.
Based on your good answers, made a custom control that
enables a Page to have several default buttons based on which panel which is in focus.
It overrides Panel's OnLoad method and DefaultButton property.