问题描述
在page1.aspx上,我在服务器端有一个与buttonOnClick事件绑定的按钮.单击按钮将运行buttonOnClick方法,该方法将生成一个对象(对于buttonOnclick方法而言是本地的),该对象包含我想在新页面的构造中使用的数据.
On page1.aspx I have a button tied to a buttonOnClick event in my server side.Clicking the button runs buttonOnClick method which generates an object (local to buttonOnclick method) with data I would like to use in the construction of a new page.
基本上,我想在新选项卡中打开一个新的(不同的)页面(page2.aspx),但是随着该页面的加载,我希望它根据buttonOnClick期间生成的对象的内容进行渲染.
Basically, I want to open a new (different) page (page2.aspx) in a new tab, but as this page loads, I want it to render based on the contents of the object generated during buttonOnClick.
如何正确处理呢?到目前为止,我一直将URL参数传递给新的弹出窗口(page2.aspx),并已将其构建为对象,但是我宁愿正确地执行此操作并生成它buttonOnclick,然后根据以下内容在弹出窗口中加载page2.aspx在buttonOnclick方法中内置的对象.
How one might go about this properly? Up until now I have been passing URL arguments to the new popup (page2.aspx) and I have it build the object, but I would rather do this properly and generate it buttonOnclick and then load page2.aspx in a popup based on what is the object built in the buttonOnclick method.
推荐答案
将对象存储在第一页的会话中,然后在第二页上检索它.
Store the object in your Session on the first page and then retrieve it on your second page.
在第一页上:
Session["myobject"] = myObject;
在第二页上:
MyObject object = (MyObject) Session["myobject"];
这篇关于在ASP.NET中将对象从一页传递到另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!