views:

143

answers:

2

With user controls on a page, I understand that every control has an impact on memory usage by storing their own state in ViewState. My question is, how much?

For example - I have a feedback form as a control on my masterpage. It is set to Visible="false" by default. A user clicks on a feedback button, and the control becomes visible while it's needed.

What would would be the relative performance impact by having control sitting there on everypage (as it's located in the masterpage), but not visible? The site I'm developing will potentially have large amounts of traffic and I wonder if I'm setting myself up for a headache later on if things become slow.

Thanks

+1  A: 

Performance could be impacted on the server and the client. Primarily you want to reduce the amount of HTML including viewstate that is sent to the client. If this sits on every page then you will send this viewstate information more often than you really need to.

I think you should have some logic that ensures that the feedback form control is only added to the feedback page. Rather than use visible="false", put it on it's own page and link to it, or dynamically add the control to the page.

The main benefits will be reduced bandwidth usage, and faster rendering of the page on the client. Secondary benefits include easier debugging and cleaner code rendering to the client.

With all performance problems you should be testing performance and making judgments based on hard data. In this case work out the size of the viewstate on the client, then multiply by number of requests to see the size of bandwidth usage on the server. On the client use a tool like FireBug to understand the overall page size received by the client.

BrianLy
A: 

It depends on the control. Datagrid with hundreds rows might generate 100k of viewstate. On the other side, checkbox won't generate too much.

You can just drop your feedback form control on empty aspx page, visit it in the browser and check for __viewstate hidden field. This is how much will you feedback form will add to each page in terms of viewstate. Then you will have to decide if it is acceptable.

I wouldn't htink about such an optimizations right at the start. If it will become slow later on, you can always change the form to be pure html and use ajax or something to post it data to server. As long as it is user control and not copy pasted content it will be easy to optimize

Alex Reitbort