Using GET and __VIEWSTATE in ASP.Net Forms

In my previous post, I described the steps to set up a form to use the HTTP GET method.

I failed to mention that this method also works for forms embedded in a MasterPage.

I showed how to clear the hidden variables, such as __VIEWSTATE, with a line of Javascript code.

However, it turns out that the presence of the __VIEWSTATE parameter in the URL defines how ASP.Net treats the other URL parameters.

If the URL contains a __VIEWSTATE parameter (even if its value is empty), ASP.Net binds the values in the URL to the controls in the form.

If it does not, you have to parse the Request parameter collection manually. To get the parameter name corresponding to a control, you need to calculate

myControl.ClientID.Replace(“_”, “%24”)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: