<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">Hi,</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y:
hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">I am busy trying to build a mobile web site with ASP.NET and for it to 100% comply with
XHTML Mobile 1.2, I need to completely disable viewstate.</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px;
top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">At the moment I just have a very simple web site with one master.page and one content page (default.aspx). For both the master.page and default.aspx pages I have put </div>
Hi,
I am busy trying to build a mobile web site with ASP.NET and for it to 100% comply with XHTML Mobile 1.2, I need to completely disable viewstate.
At the moment I just have a very simple web site with one master.page and one content page (default.aspx). For both the master.page and default.aspx pages I have put (inside page_load):
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
</title>
</head>
<body>
<form method="post" action="/default.aspx" id="aspnetForm">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE1MjQ5ODA0NjlkZKVUdXajOAHB0AuXphqwCVhfazGq" />
<div>
<span id="ctl00_ContentPlaceHolder1_Label1">
this is a test
</span>
<input type="submit" id="btnSubmit" class="hidden" />
</div>
</form>
</body>
</html>
<div>If you look at the HTML above, then you will see that ASP.NET still includes a VIEWSTATE inside a "hidden" <input> element.</div><div> </div><div>How do I prevent to get ANY viewstate included? Or alternatively, not getting the</div></div><div>
<div>directly after the <form> tag, so that it will comply?</div><div>
</div><div>I am using MVS 2008 standard, and ASP.NET 3.5.</div><div>
</div><div>I will really appreciate any/all advice.</div><div>
</div><div>Best Regards</div><div>Jan</div></div>
/* "mark as answered" when you get a reply which answers your question */
Thank you for the information, but please bear with me. (maybe this will indicate my limited abilities) but I do not get it:
In the article, Pooja Daga shows the following code:
public ShowOrdersTablePage()
{
this.Init += new EventHandler(Page_Init);
}
private void Page_Init(object sender, System.EventArgs e)
{
this.EnableViewState = false;
}
She mentions that "In this example, the page’s class name is ShowOrdersTablePage".
What executes ShowOrdersTablePage()?
For example, if I have to try and convert it to my test setup - should I use it in this way:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace mobi
{
public partial class mobile : System.Web.UI.MasterPage
{
public mobi()
{
this.Init += new EventHandler(Page_Init);
}
protected void Page_Init(object sender, EventArgs e)
{
this.EnableViewState = false;
}
}
}
Thank you for your help to understand this!
Best Regards
Jan
/* "mark as answered" when you get a reply which answers your question */
Mobile do not necessary have a fast Internet connection. If you are stuck with GPRS only, then you theoretically can get 115 kbps, but in reality after all the overheads you probably get about 60 kbps. Then memory on the mobile device is also not in all
cases as much as we would like it to be (remember that there are older phones out there as well that will visit your mobile web site).
If the viewstate for each element is saved, then it amount to quite a lot of data that accompany your actual web page. So by removing it, you make it more usable for mobile devices.
As for controlling values that you need to access in following pages, well it depends on the amount of data, but you can consider saving them in session variables, cookies, or as part of the query string.
/* "mark as answered" when you get a reply which answers your question */
JLR
Member
40 Points
21 Posts
Completely disabling viewstate
Apr 21, 2010 12:40 PM|LINK
Hi,
I am busy trying to build a mobile web site with ASP.NET and for it to 100% comply with XHTML Mobile 1.2, I need to completely disable viewstate.
At the moment I just have a very simple web site with one master.page and one content page (default.aspx). For both the master.page and default.aspx pages I have put (inside page_load):
<div>If you look at the HTML above, then you will see that ASP.NET still includes a VIEWSTATE inside a "hidden" <input> element.</div><div>
</div><div>How do I prevent to get ANY viewstate included? Or alternatively, not getting the</div></div><div>
<div>directly after the <form> tag, so that it will comply?</div><div>
</div><div>I am using MVS 2008 standard, and ASP.NET 3.5.</div><div>
</div><div>I will really appreciate any/all advice.</div><div>
</div><div>Best Regards</div><div>Jan</div></div>
dswersky
Participant
1790 Points
295 Posts
Re: Completely disabling viewstate
Apr 21, 2010 02:47 PM|LINK
Really disabling ViewState is not just a matter of setting the value to false. Here is an article with details:
http://www.ironspeed.com/articles/Disable%20View%20State%20for%20a%20Page/Article.aspx
www.daveswersky.com
Follow me on Twitter
JLR
Member
40 Points
21 Posts
Re: Completely disabling viewstate
Apr 21, 2010 04:49 PM|LINK
Hi dswersky,
Thank you for the information, but please bear with me. (maybe this will indicate my limited abilities) but I do not get it:
In the article, Pooja Daga shows the following code:
public ShowOrdersTablePage() { this.Init += new EventHandler(Page_Init); } private void Page_Init(object sender, System.EventArgs e) { this.EnableViewState = false; }She mentions that "In this example, the page’s class name is ShowOrdersTablePage".
What executes ShowOrdersTablePage()?
For example, if I have to try and convert it to my test setup - should I use it in this way:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace mobi { public partial class mobile : System.Web.UI.MasterPage { public mobi() { this.Init += new EventHandler(Page_Init); } protected void Page_Init(object sender, EventArgs e) { this.EnableViewState = false; } } }Thank you for your help to understand this!
Best Regards
Jan
JLR
Member
40 Points
21 Posts
Re: Completely disabling viewstate
Apr 22, 2010 09:27 AM|LINK
I have found my mistake (if anyone else is interested). It should be:
01.using System; 02.using System.Collections.Generic; 03.using System.Linq; 04.using System.Web; 05.using System.Web.UI; 06.using System.Web.UI.WebControls; 07. 08.namespace mobi 09.{ 10. public partial class mobile : System.Web.UI.MasterPage 11. { 12. public mobile() 13. { 14. this.Init += new EventHandler(Page_Init); 15. } 16. protected void Page_Init(object sender, EventArgs e) 17. { 18. this.EnableViewState = false; 19. } 20. } 21.}Best Regards
Jan
wahidalimi
Member
6 Points
3 Posts
Re: Completely disabling viewstate
Oct 06, 2010 09:01 PM|LINK
Why can't you use <%Page EnableViewState="False" %> ?
EnableViewState
amitkekan
Member
236 Points
65 Posts
Re: Completely disabling viewstate
Oct 11, 2010 11:45 AM|LINK
How do you manage the server control values after doing this? How is this advantageous for mobile web application?
Check out my blog: Fresh Web Developer
JLR
Member
40 Points
21 Posts
Re: Completely disabling viewstate
Oct 14, 2010 06:36 PM|LINK
Mobile do not necessary have a fast Internet connection. If you are stuck with GPRS only, then you theoretically can get 115 kbps, but in reality after all the overheads you probably get about 60 kbps. Then memory on the mobile device is also not in all cases as much as we would like it to be (remember that there are older phones out there as well that will visit your mobile web site).
If the viewstate for each element is saved, then it amount to quite a lot of data that accompany your actual web page. So by removing it, you make it more usable for mobile devices.
As for controlling values that you need to access in following pages, well it depends on the amount of data, but you can consider saving them in session variables, cookies, or as part of the query string.
alexsts1955
Member
14 Points
12 Posts
Re: Completely disabling viewstate
Aug 31, 2011 09:45 PM|LINK
QUOTE:wahidalimi wrote "10-06-2010 05:01 PM
<div class="comment-right-col"> <div>Why can't you use <%Page EnableViewState="False" %> ? "
</div> </div>===============================================
because it worked up to VS 2005, since that good luck Charlie.
VS 2008 and VS 2010 page renders with this annoying _viewstate fields.
I wonder if that was done intentionaly by Microsoft or just another bug in VS?
jberda
Member
2 Points
1 Post
Re: Completely disabling viewstate
Jul 18, 2012 06:45 PM|LINK
I struggled with this for some time until a simple solution presented itself.
Just remove it using javascript.
var vs = document.getElementById("__VIEWSTATE");
vs.parentNode.removeChild(vs);