The way to pass values between interfaces.
Attribute Value Transfer: the attribute value transfer applies to the previous and subsequent values.
Value passed by proxy: applies to the forward and backward data transfer.
Single-case transfer value: this parameter is suitable for uploading data from front to back and can be used for uploading data from back to front, but the memory space is not released until the application ends.
NSUserDefaults: a method for data persistence. data can be stored locally for a long time and then retrieved from the local device. Notification: You need to register and send notifications when using notifications.
Block: You need to define a block. When the block is called back, the value is passed to other interfaces. This applies to the back-to-back interface.
Initialization Method: Write an initialization method for the second interface. When you enter the next interface, use the value of the first interface as a parameter for the initialization method. This method is applicable to the previous and subsequent values.
Global variables: Suitable for transferring values between multiple interfaces, but the space is not released.
How do I list the methods for passing values between ASP NET pages?
1. Use QueryString variable
QueryString is a simple method for transferring values. It can display the transmitted values in the address bar of a browser. This method can be used to transmit one or more numeric values with low security requirements or simple structure. However, this method cannot be used to pass arrays or objects. The following is an example:
A. aspx C # code
Private void button#click (object sender, System. EventArgs e)
{
String s_url;
S_url = "B. aspx? Name = "+ Label1.Text;
Response. Redirect (s_url );
}
B. C # code in aspx
Private void Page_Load (object sender, EventArgs e)
{
Label2.Text = Request. QueryString ["name"];
}
2. Use the Application object variable
The scope of the Application object is global, that is, it is valid for all users. The common methods are Lock and UnLock.
A. aspx C # code
Private void button#click (object sender, System. EventArgs e)
{
Application ["name"] = Label1.Text;
Server. Transfer ("B. aspx ");
}
B. C # code in aspx
Private void Page_Load (object sender, EventArgs e)
{
String name;
Application. Lock ();
Name = Application ["name"]. ToString ();
Application. UnLock ();
}
3. Use Session Variables
Presumably, this is definitely the most common usage. Its operations are similar to those of the Application, which act on individual users. Therefore, excessive storage will result in the depletion of server memory resources.
A. aspx C # code
Private void button#click (object sender, System. EventArgs e)
{
Session ["name"] = Label. Text;
}
B. C # code in aspx
Private void Page_Load (object sender, EventArgs e)
{
String name;
Name = Session ["name"]. ToString ();
}
4. Use Cookie object variables
This is also a common method. Like Session, it is for every user, but there is a fundamental difference, that is, cookies are stored on the client, session is stored on the server. In addition, the use of cookies should be used in combination with the ASP. NET built-in Object Request.
A. aspx C # code
Private void button#click (object sender, System. EventArgs e)
{
HttpCookie cookie_name = new HttpCookie (& qu ...... remaining full text>
C # How do I pass values between common forms?
Method 1: Pass values using attributes
BackGround: ① click the Button to transfer the value of textBox1 in the main form Form1 to textBox2 in Form2. ② Click the button in Form2 to pass the value of textBox in Form2 to the text box of the main form.
1. Define a field in Form2 and encapsulate it as an attribute:
Private string flag;
/// <Summary>
/// Receive the passed Value
/// </Summary>
Public string Flag
{
Get {return flag ;}
Set {flag = value ;}
}
2. In the Form1 Button event, instantiate a Form2 form object and assign the value in textBox1 to the Flag in Form2, in this way, you can obtain the value passed in form Form1 in the form Form2 logon event.
Code in form: Form1:
Private void button#click (object sender, EventArgs e)
{
Form2 f2 = new Form2 ();
F2.Flag = textBox1.Text;
// CRITICAL REGION
If (f2.ShowDialog () = DialogResult. OK)
{
TextBox1.Text = f2.Flag;
}
}
Form: Form2 Load () event
Private void Form2_Load (object sender, EventArgs e)
{
TextBox1.Text = this. flag;
}
3. Pass a value to the parent form (return). click the button in Form2 to send the value of textBox in Form2 to the parent form Form1.
Form: code in Form2
Private void button#click (object sender, EventArgs e)
{
Flag = this. textBox1.Text;
// CRITICAL REGION
This. DialogResult = DialogResult. OK;
}
Method 2: Use the constructor in the child form (the value passed by the parent form to the child form, but the value returned by the child form is not implemented yet)
1. Reload the constructor in the form Form2
String str = String. Empty; // receives the passed value.
Public Form2 (string textValue)
{
InitializeComponent ();
This. str = textValue;
}
2. When the main form calls the subform, the parameter is passed: the Button event of the main form Form1
Form2 f2 = new Form2 (textBox1.Text );
... The remaining full text>