页面与页面之前共享数据是通过Session["ayonghu"];的方式 , 我感觉有点麻烦, 能不能新建一个类,里面放着静态变量,
一个页面要共享的数据先存进这个类的静态变量去, 另外一个页面要取用的时候, 就直接去这个类里面抓, 我感觉这样子的方式挺简单的,为什么大家不采用.

解决方案 »

  1.   


    那页面跟着的那个类是单独的吧
    不会串吧,比如下面这个代码
    public partial class Ifixed_Ifixeda : System.Web.UI.Page
    {
        DataTable idt;
        DataTable dtfi07;
        Maticsoft.BLL.Ifixedclass mbi;
        Maticsoft.Model.AYONGHU mma;
        string stclassno = "";
        protected void Page_Load(object sender, EventArgs e)
        {        
            mma = (Maticsoft.Model.AYONGHU)Session["ayonghu"];
            if (TreeView1.SelectedNode != null)
            {
                stclassno = TreeView1.SelectedNode.Value;
            }
            if (!Page.IsPostBack)   
            {
                GridView1.Style.Add("table-layout", "fixed");//列宽由表格宽度和列宽度设定。
                    mbi = new Maticsoft.BLL.Ifixedclass();
                    idt = mbi.GetAllList().Tables[0];
                    if (idt.Rows.Count < 1)
     
    请问一下,以下声明的变量
     DataTable idt;
     DataTable dtfi07;
     Maticsoft.BLL.Ifixedclass mbi;
     Maticsoft.Model.AYONGHU mma;
     string stclassno = "";
    这几个变量会不会串
      

  2.   


    不会串,但是postback后,idt, mbi会是null,因为他们只在!Page.IsPostBack中初始化了。
      

  3.   

    建议看一下Page的生命周期每次PostBack发生, Ifixed_Ifixeda 这个类都会重新构建。
    如果想在postback之间传值,可以使用Session, viewstate, cookie等。
      

  4.   

    参考:
    http://www.cnblogs.com/insus/articles/1429434.html
    http://www.cnblogs.com/insus/articles/2032508.html
    http://www.cnblogs.com/insus/articles/2055531.html
      

  5.   

    嗯,我试过,虽然是重新构建,但是如果
    public partial class Ifixed_Ifixeda : System.Web.UI.Page
    {
      DataTable idt;
      DataTable dtfi07;
      Maticsoft.BLL.Ifixedclass mbi;
      Maticsoft.Model.AYONGHU mma;
      string stclassno = "";
    被赋过值了,下次再返回的时候,值依然在哦