在ASP.NET中怎么建全局变量
比如有  01.aspx   02.aspx    03.aspx   3个页面怎么建一个变量i  (比如dim i as integer)   使i可以在该3个页面使用  (用session("变量名")太烦了)
当然,同样的, 也希望所建的子程序 ,  可以在所有的 .aspx 的页面中使用(一个页面定义一次同一个子程序也太烦了吧)
以上两问是否有答案?   如果有请指教!!!!!!!!!!!本人笨,能给出具体步骤最好!!!!!!!!!!

解决方案 »

  1.   

    session
    alpplication
    cookie
    哈哈
      

  2.   

    在ASP。NET2。0中有种很好的机制来实现楼主需的功能。

    附源码:
         例。
      SourcePage.aspx: 请注意Button1的PostBackUrl属性设置
    <%...@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">...
        public string YourName
        ...{
            get
            ...{
                return this.TextBox1.Text;
            }
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="请输入您的姓名" Width="183px"></asp:Label>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server"  Text="提交" PostBackUrl="~/TargetPage.aspx" /></div>
        </form>
    </body>
    </html>
      TargetPage.aspx:请注意PreviousPageType的属性设置
    <%...@ Page Language="C#" %>
    <%...@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">...
        
        protected void Page_Load(object sender, EventArgs e)
        ...{
            this.Label1.Text = PreviousPage.YourName;
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" ></asp:Label>
        
        </div>
        </form>
    </body>
    </html>
      OK,就通过这么简单的两个属性设置,就可以非常方便的得到跨页访问的特性。当然,您也可以根据您自己的需求,比如每个Control需要提交到不同的页面来进行更加复杂的设置。