Javascript client triggers server events

Source: Internet
Author: User

private void page_load (Object sender, system. eventargs E)
{
this.txt mediadate. attributes ["onblur"] = "_ dopostback ('" + this. linkbutton1.clientid + "','') ";
This. linkbutton1.attributes. cssstyle ["display"] = "NONE";
This. linkbutton1.click + = new eventhandler (mediadate_lostfocus );
}< SPAN class = "apple-converted-space">
private void mediadate_lostfocus (Object sender, eventargs E)
{
response. write ("wlsadfl ");
}< SPAN class = "apple-converted-space">

Http://blog.csdn.net/kucool/archive/2007/11/22/1898116.aspx

< Div >
< Input Type = "Hidden" Name = "_ Eventtarget" ID = "_ Eventtarget" Value = "" />
< Input Type = "Hidden" Name = "_ Eventargument" ID = "_ Eventargument" Value = "" />
< Input Type = "Hidden" Name = "_ Viewstate" ID = "_ Viewstate" Value = "/Wepdwullte4ndizmdg2ndrc kzmlhjobq9cycwbtbk + zrfzzkoh/I" />
</ Div >

< Script Type = "Text/JavaScript" >
<! --
VaR Theform = Document. Forms [ ' Form1 ' ];
If ( ! Theform) {
Theform=Document. form1;
}
Function _ Dopostback (eventtarget, eventargument) {
If ( ! Theform. onsubmit | (Theform. onsubmit () ! = False )) {
Theform. _ eventtarget. Value=Eventtarget;
Theform. _ eventargument. Value=Eventargument;
Theform. Submit ();
}
}
// -->
</ Script >
< Div >

In aspxCode:
< ASP: linkbutton ID = "Linkbutton1" Runat = "Server" Onclick = "Linkbutton#click" > Button1 </ ASP: linkbutton >
The source code in HTML is translated:
< A ID = "Linkbutton1" Href = "Javascript :__ dopostback ('linkbutton1 ','')" > Button1 </ A >

the above Code clearly shows that the linkbutton is just a hyperlink, the link is to execute JavaScript statements and call the backend code of the server by calling the _ dopostback function. Therefore, the _ dopostback function is automatically added to the page with a linkbutton.

but when we call the _ dopostback function, sometimes the script error" the object does not exist "will occur when we call this function? This is because there is no _ dopostback function body in HTML. When you drag and drop controls with the auto-return function, set the autopostback attribute to true, during running, the system automatically adds the _ dopostback function body. Of course, the most direct method is to add a linkbutton and set its text attribute to null. Do not set the visible attribute, if visible = false, the existence of linkbutton is ignored directly when translated into 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.