Data transfer between DOTNET forms

Source: Internet
Author: User
Data transfer between DOTNET forms

Cancersyf aspxcn.com 2002-09-02

1. webform

L use the Redirect method of httpresponse class in system. Web namespace to pass and the querystring method of httprequest class receives

Used in a method of passing the source class webform1

Response. Redirect ("webform2.aspx? S = 1 & SS = 11 ");

// Methods and attributes of the httpresponse class are exposed through the internal response object of ASP. NET.

// Therefore, response can use the former method.

Passing in the target class webform2

Private void page_load (Object sender, system. eventargs E)

{

// Place the user hereCodeTo initialize the page

Int loop1;

Namevaluecollection Coll;

// Load form variables into namevaluecollection variable.

Coll = request. querystring;

// The methods and attributes of the httprequest class are made public through the internal request object of ASP. NET.

// Get names of all forms into a string array.

String [] arr1 = Coll. allkeys;

For (loop1 = 0; loop1 <arr1.length; loop1 ++)

{

Response. Write (arr1 [loop1] + "=" + Coll. getvalues (arr1 [loop1]). getvalue (0) + "<br> ");

}

}

// This lists the values of S & SS passed from webform1.

L here I want to explain the server-side control <form runat = Server> </form> (I think) in ASP. net is only a container of controls on other servers. It can no longer use the action attribute to submit data to other pages as ASP does. The following is the original msdn text:

MS-help: // Ms. VSCC/ms. msdnvs.2052/cpgenref/html/cpconhtmlformcontrol.htm

Note that the action attribute is always set to the URL of the page. You cannot change the action attribute. Therefore, you can only send a message back to the page.

2. windowsform

L use form constructor form () to pass values.

Form class can have multiple constructors. You can add one constructor for passing values, as shown below:

Public form2 ()

{

//

// Required for Windows Form Designer support

//

Initializecomponent ();

//

// Todo: add Any constructor code after initializecomponent calls

//

}

Public form2 (int iii)

{

//

// Required for Windows Form Designer support

//

Initializecomponent ();

// Add a label to display the incoming values.

This. label1.text = III. tostring ();

//

// Todo: add Any constructor code after initializecomponent calls

//

}

You can use the following method to open form1 of form2 to pass 123 to form2:

// Windowsapplication1 is my project name

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

Frm2.show ();

L use the attributes of the class to pass the value.

Pass the following declaration of the target class form2

Private int I2;

Public int ilen

{

Get {return I2 ;}

Set {I2 = value ;}

}

// Add a label to display the incoming values.

Private void form2_load (Object sender, system. eventargs E)

{

This. label1.text = This. i2.tostring ();

}

The transfer source class form1 is used as follows:

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

Frm2.ilen= 1234;

Frm2.show ();

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.