我有三个页面,作用是查询和修改。第一个页面输入查询条件,第二个显示结果,第三个编辑单条记录。我想用一个类做,能不能在这三个页面之间共享一个类对象?

解决方案 »

  1.   

    Session[“DataSet”]
    把数据放到DataSet里
      

  2.   

    共享一个类对象
    只要你引用了都可以用呀不过你想保存数据等我想你就用SESSION吧
      

  3.   

    共享一个类对象
    只要你引用了都可以用呀不过你想保存数据等我想你就用SESSION吧====================================
    同意,不过推荐是直接共享对象
      

  4.   

    namespace WebApplication6
    {
    public class WebForm1 : System.Web.UI.Page
    {
    public c x;
    ……
    }
    }namespace WebApplication6
    {
    public class WebForm2 : System.Web.UI.Page
    {

    }
    }
    例如上面,有一个类叫c,在WebForm1中创建一个对象x,如何传到WebFrom2?除了Session外还有什么好办法?
      

  5.   

    调用Server.Transfer(不推荐)
    以下代码综合实现上述步骤过程的代码: 
    源页面代码: 
    把以下的代码添加到页面中 
    public string Name 

    get 

    return TextBox1.Text; 

    } public string EMail 

    get 

    return TextBox2.Text; 


    然后调用Server.Transfer方法 
    private void Button1_Click 
    (object sender, System.EventArgs e) 

    Server.Transfer("anotherwebform.aspx"); 

    目标页面代码: 
    private void Page_Load 
    (object sender, System.EventArgs e) 

    //create instance of source web form 
    WebForm1 wf1; 
    //get reference to current handler instance 
    wf1=(WebForm1)Context.Handler; 
    Label1.Text=wf1.Name; 
    Label2.Text=wf1.EMail; 

      

  6.   

    可以共享一个类。
    在aspx修改<%@ Page %>
    <%@ Page language="c#" Codebehind="相同的cs文件.aspx.cs" AutoEventWireup="false" Inherits="相同的类" %>注意:对于不同的页面,会实例化为不同的实例,而且注意区分访问的页面情况。