Hi,

I want to pass a value from one page to another(say from page1 to page2) & the same value again to another page(say page3).


What is the best way to do this in vb.net. Query string, Session Variables or any other method?

Thanx

“Peace comes from within. Do not seek it without.”
Anup

Dani AI

Generated

Short answer: use whichever fits the data’s sensitivity, lifetime and scalability needs. As noted, QueryString is great when the page should be bookmarkable; as pointed out, Session is the easiest server-side option. Below are practical tradeoffs and a few alternatives so the choice is clear.

Query string — pros: simple, bookmarkable, no server memory. cons: visible and user-modifiable, limited length, bad for secrets. Use for non-sensitive IDs or filters. Example (VB):

Response.Redirect("Page2.aspx?id=42")
Dim id = Request.QueryString("id")

See HttpRequest.QueryString for details: HttpRequest.QueryString (System.Web).

Session — pros: server-side, not exposed to users, good for objects and multi-page workflows. cons: uses server memory (InProc), lost on app recycle, needs special handling for web farms (StateServer, SQLServer) or persistent stores. If the value must survive across servers or restarts, persist it to DB or use an out-of-process session mode. Microsoft guidance: and .

Other options — Server.Transfer / PreviousPage (keeps context without a client redirect), POST with hidden fields (if you want to avoid URL exposure), cookies (small, client-side), or store a short token in the URL and resolve it server-side to avoid leaking data.

Recommendation: for a single non-sensitive ID used for navigation, use QueryString. For multi-step user-specific data or secrets, use Session or persist to a database (or distributed cache like Redis) and pass a short token if you need bookmarkable links. Always use HTTPS and never put secrets in URLs.

Recommended Answers

All 2 Replies

Querystring is always useful if you want the user to be able to return to such a page directly, or bookmark it.

The only other consideration is security - remember that querystrings can be modified by the user.

There are a whole bunch of ways to pass values, see here:

http://msdn.microsoft.com/en-gb/magazine/cc300437.aspx

Use Sessions
Assing Value to session variable

Session("myname") = "xyz"

To retrieve value from session

txtbox.text = session("myname")

Mark as solved if it helps you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.