In Asp. Net, scripts are often used to reconcile and pass values between pages. The following is a simple sample code for ScriptCallBack and Server. Transfer.
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
<SCRIPT language = "javascript">
<! --
Function _ doPostBack (eventTarget, eventArgument ){
Var theform;
If (window. navigator. appName. toLowerCase (). indexOf ("netscape")>-1 ){
Theform = document. forms ["Form1"]; // note the FormID
} Else {
Theform = document. Form1; // also available here
}
Theform. _ EVENTTARGET. value = eventTarget. split ("$"). join (":");
Theform. _ EVENTARGUMENT. value = eventArgument;
Theform. submit ();
}
// -->
</SCRIPT>
<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) The 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