Suppose the parentform.aspx page has a TextBox1 text box and an open button
Click the Open button to eject the Subform.aspx,subform.aspx page with the TextBox1 text box and the Close button
Clicking the Close button closes the Subform.aspx page and displays the value of the page subform.aspx text box to the Parentform.aspx text box on the parent page.
Parent form Foreground Code:
| code is as follows |
&nbs P; |
<script type= "Text/javascript" >< br> function Opensubform (ret) {
var strpath = "Subform.aspx"
var nheight = +
var nwidth = +
var feature
feature = "height=" + nheight + ", width=" + nwidth + ", Top=30,left =30 ";
feature = ", Dependent=yes,location=no, Resizable=yes,scrollbars=yes,status=yes,toolbar=no; ";
window.open (strpath+ "?) Ret_form=form1&ret_value= "+ret, ' subform ', feature). focus ();
return false;
}
</script> |
Parent Form Background Code:
| The code is as follows |
|
private void Page_Load (object sender, System.EventArgs e)
{
ペ?ジを the initial stage of するユ?ザ? コ?ドをここに Brown 毪 raft/> Br. BUTTON1.ATTRIBUTES.ADD ("OnClick", "Return Opensubform (' TextBox1 ');");
} |
Sub-form Background code:
| The code is as follows |
|
|
private void button1_ Click (object sender, System.EventArgs e)
{
string Strscript =string. Empty;
string strretform = String.Empty;
string Strretvalue=string.empty;
strretform=request.params["Ret_form"];
strretvalue=request.params["Ret_value"];
if (strretform = string. Empty)
{
strretform= "document.forms[0]";
}
strscript = "<script language=javascript > ";
Strscript + = "Window.opener." + strretform;
Strscript + + + Strretvalue + ". Value= '" + This. TextBox1.Text.Trim () + "';";
Strscript + = "window.close ();";
Strscript + = "</script>";
Response.Write (strscript);
}
|
The above is JS is actually the page to pass the value, the following I put some pages to pass the code to send the value to the reference.
Several ways to pass values between pages.
The following code fragment demonstrates how to implement this method:
Part of the code in the source page WebForm1.aspx.cs:
| The code is as follows |
|
private void Button1_Click (object sender, System.EventArgs e)
{
string URL;
Url= "Webform2.aspx?name=" + TextBox1.Text + "&email=" + TextBox2.Text;
Response.Redirect (URL);
}
Part of the code in the target page WebForm2.aspx.cs:
private void Page_Load (object sender, System.EventArgs e)
{
label1.text=request.querystring["Name"];
label2.text=request.querystring["email"];
} |
Using the session variable
Part of the code in the source page WebForm1.aspx.cs:
| The code is as follows |
|
private void Button1_Click (object sender, System.EventArgs e)
{
TextBox1 and TextBox2 are WebForm
Controls
session["Name"]=textbox1.text;
session["Email"]=textbox2.text;
Server.Transfer ("webform2.aspx");
} |
Part of the code in the target page WebForm2.aspx.cs:
| code is as follows |
&nbs P; |
private void Page_Load (object sender, System.EventArgs e)
{
&N bsp; label1.text=session["Name". ToString ();
label2.text=session["email"]. ToString ();
session.remove ("name");
session.remove ("email");
} |