views:

191

answers:

4

Hello

I have heard that we should avoid Default ASP.Net Controls, because they are heavy regarding Viewstate and etc...

So I was thinkink in using , , HTML tags whenever I want to only show information, and use the Eval function to insert server-side code in a href or src atribute.

But I have also heard that the Eval function is not the best performance solution, because it uses reflection to evaluate argument passed.

So I was planning in using explicit cast inside simple html tags.

Is this the best solution regarding performance? Do you have any other sugestion/opinion?

+3  A: 

If you're worried about things like this, then you're probably better off using ASP.NET MVC (particularly in regards to ViewState). Does your app currently have performance issues, or are you just worried about performance (the curse of the premature optimizer)?

RichardOD
The aplication isn't finished yet, but we are expecting large amounts of users per day (something arround 1000). We want to build it the best way possible, to avoid the costs of redoing parts of the program in the near future.
Marco
Can't say I would receommend switching to thhe MVC framework just because of viewstate. MVC is a system design pattern intended to address specific design problems/goals. Elimination of viewstate is a side affect of the MVC's implementation, but not one of the design goals of the MVC pattern. It is a litte like using a sledge hammer to pound in a picture hanger on your wall - it might work, but is it appropriate?Viewstate can be disabled on the application level, page level, or control level. Where we have viewstate concerns, we disabled it across the board and re-enable where needed.
James Conigliaro
1000 users a day doesn't sound like a larger number to me.
RichardOD
@James. You can disable viewstate but you can't disable control state. Of course there are lots of factors to consider when choosing ASP.NET MVC- ViewState is just one of them. ASP.NET MVC is really the Model2 pattern anyhow.
RichardOD
@RichardOD: Sorry... lolol missed a Zero: 10000
Marco
RichardOD is right. 1000 users a day is not going to need optimization. Put your money into using the simplest and quickest to write code technique. If you'd said you expected 1000 concurrent requests at a time, then I'd say you might worry about optimizing a little.
Stephen M. Redd
+2  A: 

Just use the default ASP .Net controls and disable viewstate via the properties menu.

Don't worry about the cost until you actually experience a problem.

chris
+1 for premature optimization.
Mark
I understand your answer, but i prefer to avoid problems than to fix them... fixing them sometimes is more expensive than building it right from the start.
Marco
@Marco, but so is spending ages hand rolling all your controls, only to find out the site still performs poorly under load because of some other architectural consideration you've overlooked.
Zhaph - Ben Duguid
@Zhaph: Yes I understand, and you are totaly right about time consumption. That is why we are taking a closer look to the "frequently used pages with huge amount of data". In "smaller" pages we are using productivity over performance.
Marco
@Marco: Glad to hear it :)
Zhaph - Ben Duguid
+3  A: 

Rather than avoiding ASP.Net server controls, perhaps you could think of it this way: don't use more than you need.

If you can use an HTML tag, use it. One commonly overused ASP.Net control is the Label. You only need to use the Label if you need to format it differently from your stylesheet formatting. If you just put the text in HTML, you don't need to worry about ViewState. Similarly, many people use the ASP.Net HyperLink when all they really need is an <a> .

It gets a bit more complicated with the more complex controls. All the different grids, for example. Those can be bulky, but they are very quick to write. Some of us who are working on large, enterprise, high-performance apps might write our own HTML (from code) to create a grid.

Unless performance is a big factor in your web app, then, I would suggest that you start out judiciously using the ASP.Net controls, substituting HTML for simple elements. Then, as you become more familiar with both kinds of controls, your judgment about what to use when will become better informed.

DOK
Nice answer. Thx. Do you mind if i take the chance to ask which one performs better with default paging: GridView or ListView? (althought in most cases we are using a DataGrid with Custom Paging).
Marco
Those controls may vary widely. You could test for your particular implementation by making sample web pages with each, and then examine the HTML that's rendered (use View Source in the browser). IMO, you'll get more overall performance enhancement from a grid by optimizing your data retrieval (stored procedure, table indexing, only retrieve the records you actually display, etc).
DOK
@DOK: Thx for your opinion. Yes we are already doing all those that you mentioned plus gZip, compress JS, compress CSS, compress Images, etc... this is just one more thing to take into consideration.
Marco
+2  A: 

Regarding using ASP.Net controls vs Html controls, for static content we can go for Html controls. But if you are heavily using Eval to bind data with controls, then we should use ASP.Net controls.

Regarding comaprison between Gridview and listview, my experience is that ListView is more lightweight as compared to Gridview. Gridview provides more fuctionality, but it also loads the page heavily.

Manoj
Thx, nice comment.
Marco