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 code is 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>
In a class that contains a motherboard page:
protected void Page_Load (object sender, EventArgs e)
{
This. Form.defaultbutton = "Contentplaceholder1$btsubmit";
}
Non-parent Board Page class:
protected void Page_Load (object sender, EventArgs e)
{
This. Form.defaultbutton = "Btsubmit";
}
---------------------------------------------------Another option is to make a control-----------------------------------------------------------
We all know that. How the page has only one button words. Press ENTER. can be submitted. The practice is also very simple at this time. Just write the code directly in the click. When a page is submitted, it 黓 to submit the first control. So. I put a server button with a width of 0 on top of the page to button1. It is OK to write the code to be submitted in Button1_onclick (). When running, you press ENTER to submit. This is the Button1 event that the page submits. Ha! is not very simple!
Disadvantages:
I don't need to. Each page can only have one event that is submitted by carriage return.
---------------------------------------------------Another option is to make a control-----------------------------------------------------------
Write your own control inheritance textbox, add a Submitcontrol property to specify which button to respond to when you press ENTER on this text box.
To do a converter add design-time support, you can use the Drop-down box to select the Submit button at design time.
Only button, LinkButton, and ImageButton are currently considered as the submit buttons, but the controls that inherit them are also available.
This example knowledge point: Control, property, inheritance.
Inheritance: A process by which an object can acquire attributes (including functions) of another object and add some of its own characteristics to it. As an important mechanism of the C + + language, an inherited method can automatically provide an operation and data structure for a class from another class, allowing the program designer to quickly build a new class on the basis of a generic class without having to design each class from scratch.
When a class is inherited by another class, the inherited class is called the base class, also known as the parent class.
A class that inherits other class properties is called a derived class, also known as a subclass.
In general, an inherited process originates from the definition of a base class that defines the public properties of all its derived classes. Essentially, the base class has common properties in the same set of collections, and derived classes inherit these attributes and add their own properties. The essence of inheriting from any existing class is to build a new derived class.
Implementation process
1 first create a new Project Web Control Library, add this code to the section.
public class Ufotextbox:textbox
{
[TypeConverter (typeof (Submitablecontrolconvertor)), DefaultValue (""), Category ("Behavior")]
public string Submitcontrol
{
Get
{
Object ret = this. viewstate["Submitcontrol"];
if (ret!= null)
{
Return (string) ret;
}
return string. Empty;
}
Set
{
This viewstate["Submitcontrol"] = value;
}
}
protected override void AddAttributesToRender (HtmlTextWriter writer)
{
Base AddAttributesToRender (writer);
if (this. Submitcontrol. Length >0)
{
Control con = FindControl (Submitcontrol);
if (Con!= null)
{
String script = "If" (event. KeyCode = {document. getElementById (' "+ con.) ClientID + "'). Click (); event. Returnvalue=false;} ";
Writer AddAttribute ("onkeydown", script);
}
}
}
}
Custom converter for design-time support:
public class Submitablecontrolconvertor:stringconverter
{
Private object[] GetControls (IContainer container)
{
ComponentCollection components = container. components;
ArrayList ret = new ArrayList ();
foreach (IComponent control in components)
{
if (!) ( Control ' Button control ' LinkButton control is ImageButton)
{
Continue
}
control button = [Control] control;
if (button. ID!= null) && (button. ID. Length!= 0))
{
Ret ADD (String. Copy (button. ID));
}
}
Ret Sort (comparer. Default);
return ret. ToArray ();
}
Publicoverridesystem. ComponentModel. TypeConverter. StandardValuesCollection GetStandardValues (ITypeDescriptorContext context)
{
If (context!= null) && the context. Container!= null))
{
Object[] Controls = this. GetControls (context. Container);
if (Controls!= null)
{
Return to new TypeConverter. StandardValuesCollection (controls);
}
}
return null;
}
public override bool GetStandardValuesExclusive (ITypeDescriptorContext context)
{
return false;
}
public override bool GetStandardValuesSupported (ITypeDescriptorContext context)
{
return true;
}
}
2 to generate this file. DLL file and add this DLL file to the Toolbox.
3 Drag the control into the appropriate page and add [the name of this control] to the Page_Load. Submitcontrol= "The name of the button submitted";
For example:
WebCustomControl1. Submitcontrol= "Button1" (double quotes do not remove!)
When the content is entered into the WebCustomControl1, press ENTER to Button1 the response.