1

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.

1
  • 1
    better in waht sense? like the guys say is your concern with the above route security, generalisability, the fact you have no strong typing, the fact you;re defining the name of your parameters in multiple places... any "better" solution depends on what the problem is to solve. Commented Jul 26, 2010 at 0:20

5 Answers 5

1

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();

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

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.

Comments

1

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.

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.