asp.net|server| Script | page
In ASP.net, the script callback and the values between pages are often used, and the following is a simple sample code for Scriptcallback and Server.Transfer
WebForm1.aspx
Add a __doPostBack script to the head, and if the page contains a Hyperlink button control, the script and 2 hidden controls "__eventtarget" and "__eventargument" are automatically generated by the framework, If you do not need to 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 here
} else {
Theform = document. form1;//and 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:112px; 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 values of the page's form and querrystring are preserved
}
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 the values of the form and querrystring of the page are preserved
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