ASP.NET - Viewstate Size - asp.net

Is there a reliable method for viewing the size of the viewstate on any given postback?

I would recommend using FireFox addon called "Viewstate Size". Quick, simple and convenient.
https://addons.mozilla.org/en-US/firefox/addon/5956/

Enable Trace in the web.config.
Browse the application http:////Trace.axd
In the "Control Tree" Section , sum up the ViewState Size and Control state Size of the controls.

To view it in the page at the bottom of each request you can enable page level tracing like:
<%# Page Trace="true" %>
You can read more about this technique here:
http://msdn.microsoft.com/en-us/library/94c55d08.aspx

Trace could be overkill sometimes. You can add this javascript to the page see quickly see how the ViewState grows as you click around.
<script type="text/javascript">
alert('Viewstate is now ' + $('#__VIEWSTATE').val().length + ' bytes.');
</script>

In Google Chrome you can use Chrome Viewstate or Viewstate indicator modules

You have a few options:
Using Trace
Using a browser plugin
Adding code to your project for extracting the viewstate size
I found this article quite useful "Determining an ASP.NET Page's View State Footprint" and it covers the options mentioned above.
However what I ended up doing when I needed to look at the viewstate size etc. of a application I was brought in to work on, was to use a tool called "ASP.NET ViewState Helper".
What I liked about that tool was that I could run it as a standalone executable, no installation of plugins required and no changing of the code required.
The drawback is that it only works for IE but in my case that was fine.

Related

AjaxToolkit AsyncFileUpload needs ViewStateMode enabled, how to avoid?

I know this is rather a trivial question but anyhow I want to know if it is solvable.
I have an ASP.NET webform page with a nested masterpage and JavaScript includes. I make extensive use of jQuery and Ajax calls. Once a page is loaded, all communication with the server is done with Ajax calls, so I don't need ViewState enabled, and this is resulting in a reduced HTML output code.
I now have to implement a page where a user can upload a file. So I used the AsyncFileUpload control of AjaxToolkitFileUpload. Once a file is uploaded, I do a Ajax call to the server to request the filename.
It all works fine but I noticed that FireBug found 10 errors per file upload between the OnClientUploadStarted and the OnClientUploadComplete events. The file is uploaded properly and the events on the client side are working too. But I can't ignore the fact that there are errors thrown so I went looking for the problem.
I rebuild the page piece by piece and I found out that this control needs the Viewstate enabled.
However with viewstate=disabled in the page directive the file size is 76.6kb, and with viewstate=enabled the size is 99.2kb.
Again, I know it is trivial and will not affect performance on the site, but it is a nice to know.
- Why does this control needs the viewstate? (I suppose because it actually post the file to a iFrame or something like that?)
- How can I reduce the viewstate and let this control still work properly?
For reducing view state and having this one control work properly, you can use leave view state enabled on your page and set the ViewStateMode to Disabled for the page and then set the ViewStateMode to Enabled for the one control that needs view state. For all other controls they should inherit the setting of the parent by default.

Increase the performance of asp.net page

We have one page which is about 300 KB after compression of viewstate. It's loading very slow. We are using telerik tabstrip. There are 8 user controls being loaded for this tab. Is there anyway we can improve the performance of this page? Any ideas please.
Thanks..
Yes, don't enable viewstate is one approach. Alternatively, you could load each tab on demand, so when the tab is clicked, cause a postback, and show that tab's content (which could be wrapped in a RadAjaxPanel from Telerik).
Lastly, Telerik has a rich web service model; bind the information to the UI via web services when the tab is clicked. This is something we had to do and it worked out very well performance-wise.
HTH.
You can try page level caching - here
In terms of the RadTabStrip itself you could also potentially look into using the Load-on-Demand feature as well, found on this demo page.
As for overall page efficiency if you are using the Telerik RadControls already you could look into using the RadAjax control; particularly the RadAjaxManager. This will allow you set up partial postbacks and get a more efficient page. A demo of this can be found here.
Our of the box use of the telerik tab control is not efficient. Each tab not in use STILL GETS put through the page lifecycle. There isn't anything that you can do about that out of the box, but with a little extra configuration you can gain some efficiency.
For the tab that is to be shown, you can dynamically LoadControl for the UserControl that is to be shown on the selected tab.
Have you enabled RADCOMPRESSION ?
http://www.telerikwatch.com/2009/01/optimization-tips-radcompression-module.html
You could always not use telerik! It creates such a heavy internal dependence on itself with bloated, unnecessarily complex features it makes me want to vomit. Do it yourself for best results...MVC rocks! Or just follow the answers above and get ready for lots of trial and error... :sadface:

Why Are There Multiple GET Requests Shown in Firebug?

So I'm at the stage in web programming where I'm past the "Look, Ma, I can put data in a grid and it shows up on the page." I'm now at the, wow, this site is not as snappy as I want it to be. So, I enabled the "Net" tab in Firebug, closed my eyes, crossed my fingers, and went spelunking.
The first thing I noticed is that all of my .aspx pages are being "GET"ed at least three times. Is this normal? If not, what is "normal"? What affects the "GET"ing of the .aspx pages? I'm assuming that includes the time it takes to hit the database and render all the controls on the page. Is that true?
Perhaps what would really benefit me is a place I can look to get some "best practices" for these kinds of speed related issues.
Things to consider:
Using IIS 6.0 via HTTPS
We're using Masterpages
We're using Telerik controls
A RadMenu
A RadScriptManager
I'm certainly more of a thick client guy than a web guy
EDIT
Answers to questions below:
The response code is 200
EDIT
Screen shot added:
FirebugScreenshot http://img187.imageshack.us/img187/5873/firebughelp.jpg
EDIT Added Additional Screenshot to include Request Headers
EDIT
Added links
page source
My Master file as txt
My WebConfig (without connection strings, obviously)
EDIT: Here is the source of your two extra page loads:
<script type="text/javascript"
src='<%# ResolveUrl("~/Common/jQuery/jquery-1.3.2.min.js") %>'>
</script>
<script type="text/javascript"
src='<%# ResolveUrl("~/Common/jQuery/jquery-ui-1.7.1.custom.min.js") %>'>
</script>
As you can see in the rendered version the src attribute is empty, causing it to load the page two extra times.
<script type="text/javascript" src=''></script>
<script type="text/javascript" src=''></script>
You can probably fix this by using the runat server tag and having it resolve the urls automatically.
<script type="text/javascript"
src="~/Common/jQuery/jquery-1.3.2.min.js"
runat="server"
ID="jQuery"> </script>
<script type="text/javascript"
src="~/Common/jQuery/jquery-ui-1.7.1.custom.min.js"
runat="server"
ID="jQueryUI"> </script>
(or change <%# %> to <%= %> -- since you need to have the version that outputs a string instead of the binding syntax).
Original answer removed since it was not related to the actual problem.
It's unlikely that those are AJAX requests, as the response length is the same on each request.
I'm also ruling out the bug with empty src attribute of img elements, as this only causes one reload of the page, not two.
There is a know bug with Telerik RadEditor that might cause such condition, but you don't mention it in the list of used controls. Here are more details about it:
http://www.telerik.com/community/forums/aspnet-ajax/editor/radeditor-forces-page-load-twice.aspx
You might also want to comment out the Telerik controls on the page to see if that helps.
The browser should normally hit the server just once, and all the time it takes to query the database and whatnot should be confined within that request. If you're playing around with ajax controls, they're likely to query the server more times for new data. You can use firebug to inspect the requests and responses, and see what they contain.
A common cause for the aspx being requested several times is having IMG tags rendered without any SRC attribute. This will default to querying the same page for the image source. If this is the case for you, then you could check the request headers in firebug, to see if it expects an image.
You could also go to the console and type document.images to get a list of all the images. The ones that aren't visible on the page will be shown slightly faded. Inspect those for blank SRC's.
This normally happen if you are in the Development Environment and "Enable browser link" in VS 2015/2013 .
To avoid the Multiple GET Requests Shown in Firebug, uncheck "Enable browser link" from the tool bar.
If you view the page source, you find script tag added to the page when you check "Enable Browser Link". This causes Get/Post Actions to the iis server. For more details: http://www.asp.net/visual-studio/overview/2013/using-browser-link
The browser makes a GET request for each resource included in the Page, including js files, images, css files...
It could be lots of things - the important part of the request is what it's GETing.
Generally you're going to see more than one request for an ASPX page as it loads the javascript libraries to perform validation and postbacks. Controls can also have javascript embedded as resources, which in turn create other GET requests, usually for WebResource.axd and ScriptResource.axd.
If you have security enabled, that could be the challenge and response requests - first a 401 then a 200. What are the response codes that you are getting?

asp.net: __doPostBack not rendered sometimes

We got strange error last days. ___doPostBack is undefined.
We are building quite advanced website, but not using postbacks much. One of place where postback used is ASP.NET Login Status control.
It is probabalystic, sometimes it is rendered, sometimes - not. For IE, Chrome it works mostly fine, but from FireFox it is quite high chance not to have doPostBack in page source.
Any ideas?
PS: In addition, error happens only on live environment, which uses Windows 2003 & IIS 5.0, dotnet framework is 3.5
Can it be because I am using OutputCache on page level?
Just happened to us: When googlebot or any other bot hits your page before a regular user, the page is cached without any postback options.
We did a simple hack, using different a outputcacheprofile if the request.browser.javascript is false (asp.net sends different versions of the page to those browsers/crawlers/bots)
I had the same problem, but I realized that ASP.NET does not render __doPostback when server controls don't need it.
When I put a gridview or linkbutton that need __doPostback, ASP.NET rendered it.
Yes it might be about the output cache, comment it out and try again please
Usually this happens when you have malformed javascript somewhere on the page (usually, before the __dopostback function).
Have you viewed the page source and looked to see if the __dopostback function is actually rendered in the page, regardless of whether you're getting the error or not?

How do I track down performance problems with page rendering?

I've been tasked with improving the performance of an ASP.NET 2.0 application. The page I'm currently focused on has many problems but one that I'm having trouble digging into is the render time of the page. Using Trace.axd the duration between Begin Render and End Render is 1.4 seconds. From MSDN I see that
All ASP.NET Web server controls have a
Render method that writes out the
control's markup that is sent to the
browser.
If I had the source code for all the controls on the page, I would just instrument them to trace out their render time. Unfortunately, this particular page has lots of controls, most of them third-party. Is there tool or technique to get better visibility into what is going on during the render? I would like to know if there is a particularly poorly performing control, or if there are simply too many controls on the page.
<%#Page Trace="true" %>
See http://www.asp101.com/articles/robert/tracing/default.asp.
Download ANTS PROFILER, this will give you a perfect overview of the lines causing the slowdown.
Also when it's about rendering make sure you don't use to much string concats (like string += "value") but use StringBuilders to improve performance.
It may not help if the problem is inside one of your controls - as you expect - but if the page is poorly designed and that's causing render to be slow, YSlow should help clean that up.

Resources