ASP. NET script reconciliation and server. Transfer page value transfer

Source: Internet
Author: User

In ASP. NET, you often need to use scripts to reconcile the values passed between pages. The following is a simple example of scriptcallback and server. Transfer.Code

Webform1.aspx
Add the _ dopostback script to the head. If the page contains buttons such as hyperlink, the script and two hidden controls "_ eventtarget" and "_ eventargument" are automatically generated by the framework, manually add

<Form ID = "form1" method = "Post" runat = "server">
<Input type = "hidden" name = "_ eventtarget">
<Input type = "hidden" name = "_ eventargument">
<A href = "javascript :__ dopostback ('scriptcallback', 'scriptcallback')"> scriptcallback </a>
<Asp: textbox id = "textbox1" style = "Z-INDEX: 101; left: pixel PX; position: absolute; top: 152px" runat = "server"> sometext </ASP: textbox>

C #
Webform1.aspx. CS
Private void page_load (Object sender, system. eventargs E)
{
If (ispostback)
If (request. Form ["_ eventargument"] = "scriptcallback ")
Server. Transfer ("webform2.aspx", true); // The second parameter indicates whether the form and querrystring values of the page are retained.
}

Webform2.aspx. CS
Private void page_load (Object sender, system. eventargs E)
{
If (this. Context. Handler! = Sender)
Response. Write (request. Form ["textbox1"]);
}

VB. NET
Webform1.aspx. VB
Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
If ispostback then
If request. Form ("_ eventargument") = "scriptcallback" then
Server. Transfer ("webform2.aspx", true) 'Second parameter indicates whether to retain the form and querrystring values of the page
End if
End if
End sub

Webform2.aspx. VB
Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
If not me. Context. handler is sender then
Response. Write (request. Form ("textbox1 "))
End if
End sub

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.