.NET FORM data transfer

zhaozj2021-02-17  51

Experience, if there is a mistake, please correct the Xlongjiu @ hotmail.com

Webform

l Take the Redirect method of httpresponse class in System.Web Namespace, the httprequest class QueryString method receives

Communicate in a method in WebForm1 in source

Response.Redirect ("WebForm2.aspx? S = 1 & ss = 11");

The method and attribute of the // HTTPRESPONSE class is disclosed by the internal response object of ASP.NET.

// So Response can use the former method

Pass the target class WebForm2

Private Void Page_Load (Object Sender, System.EventArgs E)

{

/ / Place the user code here to initialize the page

Int loop1;

NameValueCollection COLL;

// load form variables INTO NameValueCollection variable.

COLL = Request.queryString;

The method and attribute of the // httpRequest class is disclosed by the internal Request object of ASP.NET.

// Get Names of All Forms Into a string array.

String [] arr1 = coll.allkeys;

For (Loop1 = 0; loop1

{

Response.write (Arr1 [loop1] "=" Coll.getVALUES (Arr1 [loop1]). GetValue (0) "
");

}

}

// This lists the value of S & SS passed from WebForm1

l Here to explain the server-side control

, (I think) It is just a container of other server-side controls in ASP.NET, which can not use the Action property to others like the original ASP. Page Submitted Data. Below is the original article of MSDN:

MS-help: //ms.vscc/ms.msdnvs.2052/cpgenref/html/cpConHtmlFormControl.htm

Note that the Action property is always set to the URL of the page itself. Unable to change the action attribute; therefore, only the page itself can be returned.

Of course, the FORM that is often used in the ASP can still submit data to the ASPX page, such as the following example:

//form.htm file

// testweb .aspx file, and the former in the same directory

<% @ Page language = "c #"%> <% @ import namespace = "system"%> <% @ import namespace = "system.Web"%> <% int loop1; int loop2; namevaluecollection coll; coll = request. Form; string [] arr1 = coll.allkeys; response.write ("all: arr1.length "
");

For (Loop1 = 0; loop1 ");}}%>

// The result is that the ASPX page lists the data submitted by Form.htm.

// I just say that can only submit it to yourself,

// There is no declaration of the FORM usage of runat = Server and before.

2. Windowsform

l Use the FORM constructor form () transfer value.

The Form Class can have multiple constructors that can add a constructor for transmitting values, as follows

Public Form2 ()

{

//

// Windows Form Designer Support

//

InitializationComponent ();

//

// Todo: Add any constructor code after the initializeComponent call //

}

Public Form2 (INT III)

{

//

// Windows Form Designer Support

//

InitializationComponent ();

// Add a Label to display the resulting value

THIS.Label1.Text = iii.tostring ();

//

// Todo: Add any constructor code after INITIALIZECOMPONENT call

//

}

In a way to open the Form2 Form1, you can pass 123 to FORM2

// WindowsApplication1 is my project name

Windowsapplication1.form2 frm2 = new windowsapplication1.form2 (123);

FRM2.SHOW ();

l Use the class's attribute passage.

Passing the target class FORM2 as follows

Private Int I2;

Public INT Ilen

{

Get {Return I2;}

Set {i2 = value;}

}

// Add a Label to display the resulting value

Private Void Form2_Load (Object Sender, System.EventArgs E)

{

THIS.LABEL1.TEXT = this.i2.toString ();

}

Transfer source FORM1 is used as follows

Windowsapplication1.form2 frm2 = new windowsapplication1.form2 ();

FRM2.ILEN = 1234;

FRM2.SHOW ();

转载请注明原文地址:https://www.9cbs.com/read-30708.html

New Post(0)