Use the _ doPostBack event

Source: Internet
Author: User

<% @ 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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.