ViewState(???) QueryString problem

My problem is that when I press a submit button, the current querystring of that page is submitted to the processing pages in postback.

This is how my pages work:

You goto the page and it fills in the current information if not postback

If it is postback, it checks for the type of action requested and processes the page.
Then if processing occured correctly, it response.redirects the user to the page they're currently on with a message sent in query string


A problem occurs when they make a successfull pass and then have an error.
What it ends up doing is passing the querystring to the page again after a postback, so it reads the message from the LAST process and prints it on the screen, with an error message.

You end up getting:
There was an error in the following fields...
You have updated successfully.

(In reality it did not update, thats just from the QS)
digitalpacmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

digitalpacmanAuthor Commented:
I found the exact problem, but I don't know how to handle it.

Apparently with viewstate enabled, the form action is ALSO put into a viewstate.

It places the querystring that comes with the page into the viewstate.. this was working very well without my notice for a while, until I changed the way the pages refreshed. Now its a problem.

How can I make the action of the form not part of the viewstate?
appariCommented:

can you post your existing code
digitalpacmanAuthor Commented:
page.aspx
<span id="message" class="message" runat="server"></span>


page.vb
   If Len(Request.QueryString("message")) > 0 Then
      Me.message.InnerText = Request.QueryString("message")
    Else
      Me.message.InnerText = ""
    End If

... process commands...

...if process was successful then...
Response.Redirect("page.aspx?message="Success!")
...end...
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

appariCommented:
what is the need for using response.redirect? you are displaying in the same page so i think you can directly display the message like this,
'**** the following block is not required
'  If Len(Request.QueryString("message")) > 0 Then
'      Me.message.InnerText = Request.QueryString("message")
'    Else
'      Me.message.InnerText = ""
'    End If
'**** remove till here
... process commands...

...if process was successful then...
'*** delete the following and relpace it with the next statement
'Response.Redirect("page.aspx?message="Success!")
Me.message.InnerText = "Success!"
...end...
digitalpacmanAuthor Commented:
Well you know that really annoying "To view this page you must resubmit... blah blah" error? Well people don't like that error, and if they hit cancel they lose the page and don't know what to do.

The page im making is for a very computer illterate person. He would probably call us asking what the problem is if he ever saw that problem.

SO a response redirect gets rid of that problem all together.. this is why it is a requirement to use a response redirect.
appariCommented:

that case you change your code structure to something as follows.

1. check for errors
2.  a) if no errors and querystring has success message then display success message
     b) if errors exist and querystring has success message then display Error message and ignore success message
     c) if errors exist and querystring has no success message then display Error message

if you can post complete code from page_load event i can change.
digitalpacmanAuthor Commented:
the message in the querystring can store error or success messages. they are displayed in the same place

what do you want me to do, put into the querystring if there were errors?

Plus, if an error occurs, then postback happens with no redirect. My custom success message is clashing with the validation control error message, because the querystring is always written to the form action element. This is why I asked if I could take off asp.nets ability to copy the URL and the querystring to the form action. I would rather it be static like in every other programming language.

Your format does not work, because I am using validation controls and there is a response redirect only if there is a success.

When the page is reloaded with a querystring then the querystring is printed. The problem is the querystring stays within the form element forever. I cannot remove it from the querystring because its put into the form action element. So the next time they submit, the proces page gets the querystring everytime.

What you are asking me to do, is to add the querystring only if there was a success, and then put into the querystring a variable that says it was a success. But then that just gets copied to the form action tag. then every post it gives from there on, will be believed to be a success with a success message.

I found a way to solve it that I am not happy with, I want this to be a temporary solution. I am really searching to get rid of the copying of the URL to the form action tag. There is no enableviewstate for the form element, so I am totaly lost of what to do. Possibly it could be a configuration of the web.config file? I do not know. Is it an option in the page derivative declarement where you specify the codebehind and inheritance?

The temporary solution I decided on was to set the message that I want to display into a session variable, and clear it everytime it is printed. I use this method at work, but I don't like it there either. I don't like the idea of storing entire sentences inside a session.
appariCommented:
we cannot change the action parameter of the form in .net. so if your page url is xxxx.aspx?queryStr=aaaa it submits to xxxx.aspx?queryStr=aaaa only. we cannot change it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
digitalpacmanAuthor Commented:
Well that's horrible..

How do you personally normally handle displaying error exceptions to the user?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.