Passing data between asp.net pages

元气小坏坏 提交于 2019-11-29 05:05:30

Session is probably the most efficient. However, if the session times out or is lost for any other reason, any entries are lost. So if persistence is more important, you may want to store it in the db.

Alex

Maybe Cross-Page Posting option?

Another option could be Server.Transfer method together with Context.Items or Form property.

In this case any posted form variables and query string parameters are available to the second/third/etc. page as well.

But the URL in browser won't be changed until you really transferred to another page.

One thing to be aware of is that if the first page wrote something to the Response buffer and you don’t clear it, then any output from the second page will be appended to the output of the first. This is often the cause of a weird behavior where it seems that a page is returning two different pages. Also, since the transfer happens on the server, you cannot transfer a request to an external site.

More information could be found here.

Passing the Values via Session variables doesn't work too well. You might also have chances where the user hits the back button or clicks refresh and the session variables have been garbage collected. This is the way for any cached items. One way around this is when the user goes to the second page, you take all the variables and put them into a hidden field somewhere separated by a Key:Value pair.

If the values can put put into the open, why not just put them into the URL?

If you can't do either, then putting them into a database and giving them a Guid ID per the username, that would prolly be the last alternative for me since you have to both read and write to the DB on each request.

The answer is entirely dependent on what the user expects the next time he returns to your site. Does he expect you to remember the contact information he already entered? If so, then you're going to have to use long term persistence in a database, cookie, etc. Is your user entering someone else's information for this visit only (i.e. a customer service app), and will enter different information the next time they visit? If so, then you may want to use the Session object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!