Get the App
SLTechnology News&Howtos  ›  Development  › 

How to transfer values between forms by ASP.NET

Shulou Source: shulou.com Published: 2022-06-03 07:45:40 11月15日 Update

This article will explain in detail how to transfer values between forms in ASP.NET. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Suppose there are TextBox1 text boxes and Open buttons on the ParentForm.aspx page

Click the Open button to pop up the SubForm.aspx,SubForm.aspx page with TextBox1 text box and Close button

Click the Close button to close the SubForm.aspx page and display the value of the child page SubForm.aspx text box on the parent page ParentForm.aspx text box.

Foreground code of the parent form:

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

}

Background code of the parent form:

Private void Page_Load (object sender, System.EventArgs e)

{

/ / in the initial phase of the program, we need to know that we are going to enter the hospital.

This.Button1.Attributes.Add ("onClick", "return OpenSubForm ('TextBox1');")

}

Sub-form background code:

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 = ""

StrScript + = "window.opener." + strRetForm

StrScript + = "." + strRetValue + ".value ='" + this.TextBox1.Text.Trim () + "';"

StrScript + = "window.close ();"

StrScript + = ""

Response.Write (strScript)

}

This is the end of this article on "how to transfer values between ASP.NET forms". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Tags: Forms pages buttons text code articles background more good practical content early stage foreground handles articles knowledge references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB Docker macOS NVidia