I have a site that is set up to validate the user from time to time. Every time the user is validated the user is redirected to the login page, which is another web application under IIS. Since the user is still valid it will be redirected back, but during this time it has lost the postback data making the whole form set to default.
My first thought was to just turn off view state on the form and use get instead of post on the form tag
<form runat="server" method="get" enableviewstate="false">...</form>
The get command works, but the querystring get the view state is printed maki开发者_C百科ng the url to long. Is there some easy to solve this? Basically what I want to do is to turn off viewstate completely, I've tried to use the enableviewstate
, but I can't get it to dissapear.
Have you tried setting the enableViewState property within web.config so you'd have something that looks like:
<pages enableViewState="false">
....
</pages>
You can disable viewstate across your application using Grant's suggestion. Alternatively, you could turn it off for a single page in the Page's declaration. For example:
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" EnableSessionState="ReadOnly" %>
The title contradicts the problem slightly, as it seems that your actual issue is that although you have set EnableViewState=False
you are still getting the viewstate written to the page as hidden variables.
This question is along the same lines, but you still get hidden fields written even if you use these two methods:
Your own PageStatePersister:
public class EmptyStatePersister : PageStatePersister
{
public EmptyStatePersister(Page page) : base(page) { }
public override void Load() { }
public override void Save() { }
}
protected override PageStatePersister PageStatePersister
{
get
{
return new EmptyStatePersister(this);
}
}
Your own page class, as the question linked describes:
public class EmptyViewStatePage : Page
{
public override bool EnableViewState
{
get
{
return false;
}
set
{
base.EnableViewState = false;
}
}
protected override void SavePageStateToPersistenceMedium(object state)
{
}
protected override object LoadPageStateFromPersistenceMedium()
{
return null;
}
}
So you're left with jQuery:
<script type="text/javascript">
$(document).ready(function ()
{
$("#__EVENTVALIDATION").remove();
$("#__VIEWSTATE").remove();
});
</script>
精彩评论