An explanation of the method of implementing value between ASP

Source: Internet
Author: User

Suppose there are TextBox1 text boxes and open buttons on the parentform.aspx page
Click the Open button to eject the Subform.aspx,subform.aspx page with the TextBox1 text box and the Close button
Click the Close button to close the Subform.aspx page and display the value of the page subform.aspx text box to the text box parentform.aspx the parent page.

Parent form Foreground Code:

Code to copy code as follows
<script type= "Text/javascript" >
function Opensubform (ret) {
var strpath = "Http://www.111Cn.NeT/subForm.aspx"
var nheight = 500
var nwidth = 500
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)
{
ペ?ジを in the early stages of するユ?ザ? コ?ドをここに Brown in raft/> this. BUTTON1.ATTRIBUTES.ADD ("OnClick", "Return Opensubform (' TextBox1 ');");
}

Child 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);
}



Above is the JS is actually the page value, the following I put some page value code for reference.

Several ways to transfer values between pages.

The following code snippet 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 Session Variables

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:

The code is as follows
private void Page_Load (object sender, System.EventArgs e)
{
label1.text=session["Name"]. ToString ();
label2.text=session["Email"]. ToString ();
Session.remove ("name");
Session.remove ("email");
}

The above two are commonly used in the other is not introduced, we can refer to their own

An explanation of the method of implementing value between ASP

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.