Is there a way to change the query strings without breaking ASP.Net postback?

From reading here and around the net, I'm close to assuming the answer is no, but ...

Let's say I have an ASP.Net page that sometimes has a query string parameter. If the page has a query string parameter, I want to disable it before, during, or after postback. There are already many client-side script on the page (pure JavaScript and jQuery).

As an example, let's say that I am loading:

http://myPage.aspx?QS=ABC

      

The QS parameter is needed to control what appears on the page on first load and is set by the page that "names" it. myPage.aspx

has form elements that you need to fill out and has a submit button that does the postback. When the page finishes postback, I need to return the url:

http://myPage.aspx

      

to avoid client side code that gets called when the query string is present. In other words, after submitting, I do not want the client-side actions associated with the query string parameter to take place. I know I could add the form content to the url as query string parameters and just redirect to the new url and avoid submitting / posting back, but that would require a lot more type checking in code to avoid bad data and random substitution. I assumed that I could also set a hidden field in the codeb and look at it along with the query string to reverse the client-side behavior if I return from a postback, but that still leaves the chain of requests unchanged forever and I want to get rid of it after the initial page load.

Any ideas or best practices?

PS - Can I do something with the Form.Action property that doesn't break the postback behavior?

+1


source to share


3 answers


I'm not sure if this is what you are looking for, but if you understand correctly, you can do this:

- checking the page load for the QS value, if it does not use a hidden input field.

- first page load with QS, your normal processing and storing the QS value in a hidden input field.



- if QS does not use hidden input value

-After postback you can redirect to the same page, at that point you can user Request.Form [] get hidden input field, still load data correctly, but get rid of QS.

it made sense in my head, I'm not sure if it makes sense now, but I'll let you decide.

+1


source


I would use the HTTPModule to intercept and rewrite the url and request when it came. m is not 100%, but I don't think it affects the viewstate.



It sounds (and looks) complicated, but it's actually quite trivial and open to a ton of refinement and extension (as in .NET in general).

+2


source


This is most likely bad practice, but in those cases (and I just need to "reset" the page), I just do a Response.Redirect on the same page.

+1


source







All Articles