Methods for passing values between ASP. NET forms

Source: Internet
Author: User

Assume that the ParentForm. aspx page contains TextBox1 text box and Open button.
Click the Open button to bring up SubForm. aspx. The SubForm. aspx page contains the TextBox1 text box and the Close button.
Click Close to Close the SubForm. aspx page, and display the value of the SubForm. aspx text box on the subpage to the ParentForm. aspx text box on the parent page.
Front-end code of the parent form:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function OpenSubForm (ret ){
Var strPath = "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>

Background code of the parent form:
Copy codeThe Code is as follows:
Private void Page_Load (object sender, System. EventArgs e)
{
// Zookeeper early stage of transformation zookeeper
This. Button1.Attributes. Add ("onClick", "return OpenSubForm ('textbox1 ');");
}

Subform background code:
Copy codeThe Code is as follows:
Private void button#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 );
}

Related Article

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.