I tried this and copied the name of the button into the panel button. I got the following error: The DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl. Description: An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl I copied
the exact name, LoginButton and now I get this error.
Any one create more then one submit button in the application. Here is the Example. That create more then one submit button depending on the focus of the text button before hit enter.
Call makeSubmitButton on the page_Load and pass the textBoxId and also ButtonId which you want to make submit button when focus is on txtBoxId.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pradeep Kr. Sharma
http://vshelpdesk.blogspot.com/
Please Mark As Answer, which helped you. So that it might be useful for others.
stapes
Member
121 Points
124 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
May 14, 2008 04:30 PM|LINK
rmdw - Could you explain that code?
rmdw
Participant
825 Points
1235 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
May 14, 2008 05:35 PM|LINK
That's a very vague question. What precisely do you want to know?
The key line is this one in the Page_Load event handler: Page.Form.DefaultButton = buttonSubscribe.UniqueID;
Robert
Vancouver, BC
Technical Blog
Pocket Pollster
liju.thn
Member
75 Points
341 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Sep 25, 2008 06:02 PM|LINK
hi all i have got a fine piece of code for the master - content page issue of default submit buttons .put this in page load of master page
txtpwd.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+btnsubmit.UniqueID+"').click();return false;}} else {return true}; ");
SigHandel
Member
17 Points
4 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Nov 04, 2008 06:13 PM|LINK
hemens
Member
3 Points
32 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Nov 19, 2008 08:21 AM|LINK
Hii,
I tried the above in form tag of my default page, but it gives error stating " form1 button id should be of I BUTTON CONTROL.
I am calling user control in home page, so my form tag is in home page and defaultbutton thing is not working as not able to find i gues...
how do i resolve...
....hemens
rmdw
Participant
825 Points
1235 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Nov 19, 2008 08:06 PM|LINK
Hi Everyone,
It has been a while since I wrote that code. I just tested it and it works fine. Here's proof: http://pocketpollster.com/beta
Looking at it now, the pertinent code only appears to be this:
<asp:Button ID="buttonSubscribe" CssClass="smallTextButton" runat="server" Text="Subscribe" OnClick="buttonSubscribe_Click" ValidationGroup="Newsletter" />
And:
protected void Page_Load(object sender, EventArgs e)
{
// Make the Newsletter Subscribe button the default button
if (!IsPostBack)
{
Page.Form.DefaultButton = buttonSubscribe.UniqueID;
}
}
I'm by no means the expert in this area, but what I've written does work for me. Hopefully it'll help you.
Robert
Vancouver, BC
Technical Blog
Pocket Pollster
codemobile
Member
134 Points
98 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Dec 09, 2008 10:43 AM|LINK
WHat in case of multiple default buttons ? Can i use multiple ?
Pradeep Kr. ...
Participant
1712 Points
294 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Jan 16, 2009 06:11 PM|LINK
Hi,
Any one create more then one submit button in the application. Here is the Example. That create more then one submit button depending on the focus of the text button before hit enter.
Call makeSubmitButton on the page_Load and pass the textBoxId and also ButtonId which you want to make submit button when focus is on txtBoxId.
It will set ButtonId as a default button....
public void makeSubmitButton(System.Web.UI.WebControls.TextBox txtBox, System.Web.UI.WebControls.LinkButton CmdButton)
{
txtBox.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + CmdButton.UniqueID + "').click();return false;}} else {return true}; ");
}
Sincerely,
Pradeep Kr. Sharma
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://vshelpdesk.blogspot.com/
Please Mark As Answer, which helped you. So that it might be useful for others.
Shailendra S...
Member
71 Points
34 Posts
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Jan 17, 2009 06:47 AM|LINK
following code is for default button.
<form id="form1" runat="server" defaultbutton="btnlogin" >
--
--
</form>
Vitesh Tande...
Member
2 Points
1 Post
Re: ASP.NET 2.0 - Enter Key - Default Submit Button
Jan 26, 2009 05:34 AM|LINK