将对象数据从一页发送到另一页 [英] Send an Object data from one page to another

查看:64
本文介绍了将对象数据从一页发送到另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些文本框和下拉列表的页面,现在我使用了一个具有某些属性的.cs类,并在.aspx页面中设置了属性类的对象.现在,我想将这些值传递给下一页,在这里我调用返回datset并设置为listview的.cs类的另一种方法.表示默认值.现在,我现在要使用以前的值,这里一次设置属性的解决方案是什么,可以在其他页面上使用,但是我需要一个单独的对象来调用该方法,而我现在没有办法.所以请帮助我克服这个问题.

例如
JobSearch.aspx.cs到Jobs.aspx.cs
Jobsearch具有所有控件,而Jobs只需使用新对象调用jobs.cs类方法.

I have a page with some textbox''s and with dropdownlist now i have used a .cs class with some properties and set properties class''s object in .aspx page. Now I want to pass these values to the next page where i am calling another method of .cs class that returns datset and set to listview now i have problem that if i want to call that i need a separate object that sets separate values to properties means default values. Now i want to use previous values now what is the solution here to set the properties once and can use on other page but i have need a separate object to call the method i have no way to got now. So please help me overcome this problem.

e.g.
JobSearch.aspx.cs to Jobs.aspx.cs
Jobsearch has all the controls and Jobs just call the jobs.cs class method with new object.

推荐答案

使用Session.像这样:
Use Session. like this:
//First page
MyClass c1 = new MyClass();
Session["MyClass"] = c1;

//Next page
MyClass c1 = Session["MyClass"] as MyClass;
if (c1 != null) {
 ...
}


使用会话:
例子:

classtest t = new classtest()//来自被称为classtest的类的对象
会话["obj"] = t;

现在,当您要检索它时,请执行以下操作:

classtest n = new classtest()

n = Session ["obj"];

请注意,如果不使用inproc,则在会话中保存对象时应将其序列化.

希望对您有所帮助.
Use sessions :
Example :

classtest t=new classtest() //object from a class callaed classtest
Session["obj"]=t;

now when you want to retrieve it juts do the following :

classtest n=new classtest()

n=Session["obj"];

Kindly notice that when saving object in session it should be serialized if you are not using inproc.

Hope this helps.


看看这篇文章.应该有帮助.

http://aspalliance.com/151_Passing_Data_the_NET_way [ ^ ]
Have a look at this article. Should help.

http://aspalliance.com/151_Passing_Data_the_NET_way[^]


这篇关于将对象数据从一页发送到另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆