Use Server Controls Only When Appropriate


If you need to access an HTML element's properties, methods , or events in server-side code, you have to declare it as a server control. It is always worth considering which elements actually need to be server controls when you build a page. For example, the following situations do not require a server-side control:

  • When the element is only used to run some client-side script “for example, a button that opens a new browser window, or interacts with a client-side ActiveX control or Java applet, or calculates some value for display in the page using DHTML, or in an alert dialog.

  • When the element is a hyperlink that opens a different page or URL and there is no need to process the values for the hyperlink on the server.

  • When access to the element's properties, methods, or events in server-side code is not required.

A page containing server controls will take a performance hit compared to one that does not use server controls, perhaps as much as 30 percent. However, using code to set or access the element content directly will also cause a performance hit, so if you do need to access the element programmatically (even just to set the text or value), use a server control for that element.




Professional ASP. NET 1.1
Professional ASP.NET MVC 1.0 (Wrox Programmer to Programmer)
ISBN: 0470384611
EAN: 2147483647
Year: 2006
Pages: 243

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net