Asp. NET how to transfer data between forms and forms

Source: Internet
Author: User
Asp.net| data Everyone knows that ASPX is very easy to pass values in the same page (such as TextBox1.Text, etc.) but sometimes it has to be passed to another page. In the previous ASP method does not feel good, but also to use request.form and other things as if back to the past. I'm here using a static property of a class as a global variable of two classes to achieve a two-page pass value. A simple example is as follows:


First, define a class that contains static properties:
Using System;


Namespace study
{
<summary>
Summary description of the CIndex.
</summary>
public class CIndex
{
public static string Name= "";
Public CIndex ()
{
}
}
}


It is then written in a page containing information submission:
<%@ Page language= "C #" codebehind= "Submit.aspx.cs" autoeventwireup= "false" inherits= "Study.submit"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>submit</title>
<meta name= "generator" content= "Microsoft Visual Studio 7.0" >
<meta name= "Code_language" content= "C #" >
<meta name= "vs_defaultClientScript" content= "JavaScript" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
</HEAD>
<body ms_positioning= "GridLayout" >
<form runat= "Server" id= "Form1" >
<asp:textbox id= "TextBox1" runat= "Server"/>
<asp:button text= "Submit" runat= "Server" id= "Button1"/>
</form>
</body>
</HTML>


Codebehind:
First introduce the study namespace
Using study;
Then add the Button1 click event
private void Button1_Click (object sender, System.EventArgs e)
{
cindex.name=textbox1.text;//the static properties of the class to the value that will be passed to another page
Response.Redirect ("getsubmit.aspx");
}


Then add the following code to the codebehind in the other page:
private void Page_Load (object sender, System.EventArgs e)
{
Response.Write ("You enter the parameter value is:" +cindex.name);
}




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.