Reputation: 20078
what is the best way of passing querystring to another page, i would definitly avoid like using.......
<a href="Page2.aspx?WONumber=12345">
is there any better way?
i was thinking create a Baseclass with few prop and update the baseclass?
thanks.
Upvotes: 1
Views: 643
Reputation: 2638
There is a great article I came across a few months ago when I was looking for enhanced security with querystrings...
http://devcity.net/Articles/47/1/encrypt_querystring.aspx
It's a very good article, and has a bonus the author offers code examples in C# and VB.NET.
There are times when I prefer to use querystrings over sessions... small number of session objects is ok, but too many and it starts to become a bit tedious to debug problems.
Upvotes: 1
Reputation: 1018
If your objection is the maintainability of "magic string" URLS, and you'd be prepared to use a button instead of an anchor, you could do worse than
<form method="GET" action="Page2.aspx">
<input type="hidden" name="WONumber" value="12345" />
<input type="submit" value="Navigate" />
</form>
this method will generalise to a query string of any complexity with any number of parameters.
Upvotes: 1
Reputation: 61971
It really depends on where you're getting the value from. You can build a URL using UriBuilder
or if it's simple enough string concatenation could be OK (though you'd have to make sure to Server.UrlEncode
the values).
If the value is a constant, as your example implies, then there is nothing wrong with putting it directly into a query string, although I would still use a proper named constant, eg.
<a href="Page2.aspx?WONumber=<%= TheMagicOrderNumber %>
with the constant defined in the code-behind:
protected const int TheMagicOrderNumber = 12345
Upvotes: 1
Reputation: 1364
You can encrypt a querystring parameter, if security is your concern.
Or you can use other holders, such s p.cambell says above (session & cookie).
You could also store it in a database, and have the page you go to retrieve it onload.
Just depends on your application requirements.
Another thing I've done is to use <asp:panel>
, basically using a single page as though it were multiple pages. In this way, I also have access to viewstate to hold my variables. (Whenever a user clicks 'next', or whatever they would click to goto the next page, I simply hide the panel they're on, and show the panel they want to go to [visible = true/false] property)
Upvotes: 0
Reputation: 100557
It sounds like you want to take the querystring argument, and use it in subsequent pages.
If it's not desirable to pass-forward this querystring argument from your current page, perhaps it's called page1.aspx
, without using another querystring parameter, you could:
store the value in Session
. Consider Session["WoNumber"] = Request.QueryString["WONumber"].ToString();
store the value in Cookies
. You could use something like: Response.Cookies["WoNumber"].Value = Request.QueryString["WONumber"].ToString();
Upvotes: 1