<% @ Page Language = "C #" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Script runat = "server">
Protected void Page_Load (object sender, EventArgs e)
{
// Obtain TextBox1
String cname = Request. Form ["_ EVENTTARGET"];
// Obtain the Text value of TextBox1
String cvalue = Request. Form ["_ EVENTARGUMENT"];
If (cname! = Null & cvalue! = "")
{
This. Label1.Text = "Control name" + cname + "Control Value" + cvalue;
}
}
</Script>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> No title page </title>
<Script language = "javascript" type = "text/javascript">
Function submitTextBox1 (){
Var txtBox1 = document. getElementById ("TextBox1 ");
_ DoPostBack ("TextBox1", txtBox1.value );
Return false;
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
Submit the text box content to the server using javascript code <br/>
<Asp: TextBox ID = "TextBox1" runat = "server"> </asp: TextBox>
<Br/>
Text Content: <asp: Label ID = "Label1" runat = "server" Text = "Label"> </asp: Label> <br/>
<Asp: Button ID = "Button1" runat = "server" OnClientClick = "return submitTextBox1 ();"
Text = "doPostBack"/>
<Br/>
<% -- The autopostback attribute of dropdownList1 must be set to true to automatically generate the _ doPostBack function on the page.
Two hidden buttons are generated on the page.
One name is _ EVENTTARGET and the other name is _ EVENTARGUMENT.
The first value is the name of the control that triggers the event.
The second value is the parameter -- %>
<Asp: DropDownList ID = "DropDownList1" runat = "server" AutoPostBack = "True" Width = "0px">
</Asp: DropDownList>
</Div>
</Form>
</Body>
</Html>