Asp. NET Carriage return Commit event in fact, is not asp.net programming problem, but is about the HTML form of the Submit button is how to plan the specific discussion. Also can be attributed to ASP.net programming part, then asp.net carriage return submission Event's concrete realization is what? Below we have a specific look at:
ASP. NET carriage return commit event implementation 1,
When your cursor focus enters a FORM element, it activates the first (if any) button in the form (the flow layout obeys left to right, top to bottom) Type=submit, waits for a response to the carriage return event, and submits the form
You can test the code:
Copy Code code as follows:
﹤form action= "" ﹥
﹤input type= "Text"/﹥
﹤input type= "Submit" value= "Submit"/﹥
﹤/form﹥
﹤form action= "" ﹥
﹤input type= "Text"/﹥
﹤input type= "button" value= "Submit"/﹥
﹤/form﹥
ASP. NET carriage return commit event implementation 2.
button in ASP.net 2.0 is rendered as ﹤input Type=submit﹥ this time no additional script submission form, the Submit button is designed to submit form and in 1.x is presented as ﹤input Type=button Onc Lick=_dopostback (...)/﹥ this normal button does not have the default behavior of Submit
Asp. NET carriage return commit event implementation 3. Disabling this default behavior has Law II
(1) Set the Defualtbutton of the form element to the real button you want to respond to carriage return as follows
Copy Code code as follows:
﹤form id= "Form1"
runat= "Server"
defaultbutton= "Button1" ﹥
Note DefaultButton =﹤﹤targetbutton.id﹥﹥ so this may not be valid for a Button in a composite control such as a template (not tested)
(2) Modify button rendering Usesubmitbehavior= "false"
Copy Code code as follows:
﹤asp:button id= "Button1"
runat= "Server" text= "button"
onclick= "Button1_Click"
Usesubmitbehavior= "false"/﹥
In addition, by controlling the focus of the way, filter return practice, you need to record a note, get the current page focus of the control's ID:
Document.activeelement
For asp.net. After we enter the content in the TextBox1, press the ENTER key to execute the Button1 click Method. Then write in the Page_Load event method.
Copy Code code as follows:
TEXTBOX1.ATTRIBUTES.ADD ("onkeydown",
"If" (Event.which | | Event.keycode) {
if ((Event.which = 13) | | (Event.keycode = 13)) {
document.getElementById (' "+
Button1.uniqueid+ "'). Click (); return false;}}
else {return true}; ");
There is a asp.net inside the form of the form runat=server, when the inside of the ﹤asp:button. You can't always press a carriage return to submit the form, it is very unpleasant.
Now finally found a property that can do this thing with this. Form.defaultbutton = "Contentplaceholder1$btsubmit";
It is worth noting that if you use the MasterPage (Motherboard page), then add the motherboard to the button ID before the Id:contentplaceholderid and a dollar character ($)
The C # implementation code is as follows:
Copy Code code as follows:
﹤%@ Page language= "C #"
Masterpagefile= "~/masterpage.master"
Autoeventwireup= "true"
Codefile= "Login.aspx.cs"
inherits= "Login"%﹥
﹤asp:content id= "Content1"
Contentplaceholderid= "ContentPlaceHolder1"
runat= "Server" ﹥
﹤asp:textbox runat= "Server"
Id= "WD" ﹥﹤/asp:textbox﹥
﹤asp:button id= "Btsubmit"
runat= "Server" text= "Submit"
onclick= "Btsubmit_click"/﹥
...........................
﹤/asp:content﹥
(1) In a class containing a motherboard page:
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
This. Form.defaultbutton = "Contentplaceholder1$btsubmit";
}
Or on the content page
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
This. Page.Form.DefaultButton = "Contentplaceholder1$btsubmit";
}
(2) Non-motherboard pages in the class:
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
This. Form.defaultbutton = "Btsubmit";
}
Asp. NET carriage return submission event details to you here, I hope that you understand and learn asp.net carriage return to submit the event to help.