Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

When to override Render

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Allan Ebdrup - 23 Jul 2007 13:09 GMT
We're pretty new to ASP.Net 2.0 and we're having a discussion about best
practice when developing custom server web controls.
I can see that in for example the Wizard control the table contained within
is a control and all the children are controls.
That seems to be a good practice to me, use controls when possible.
On the other hand one of the developers here wants to override the Render
methods and create child tables with strings and a HtmlTextWriter.
In my view that introduces a lot of problems since you can easily make a
mistake in the Html you output, and you don't get any programatical access
to all the children that you have if you use controls.
On the other hand the developer here thinks that all those controls make a
mess, he just want the children of the control to be the stuff that actually
matters, not stuff like tables that are just there for layout purposes.

What's your take on this? What's a good practice? Use controls whenever
possible and only override the Render methods when you absolutely have to?
Or override the render methods every time you can?

Kind Regards,
Allan Ebdrup
John Timney (MVP) - 23 Jul 2007 13:51 GMT
Controls whenever possible. Overriding render should be done only when you
need to, just like developing any code.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog

> We're pretty new to ASP.Net 2.0 and we're having a discussion about best
> practice when developing custom server web controls.
[quoted text clipped - 17 lines]
> Kind Regards,
> Allan Ebdrup
Peter Bucher [MVP] - 23 Jul 2007 21:58 GMT
Hi John, hi Allan

> Controls whenever possible. Overriding render should be done only when you
> need to, just like developing any code.
I agree with you: when you need to!

Its important to know, whats really goin on.
Use .NET Reflector for this.

The Render Methode looks like:
-----
protected internal override void Render(HtmlTextWriter writer)
{
   this.RenderBeginTag(writer);
   this.RenderContents(writer);
   this.RenderEndTag(writer);
}
-----

As you`ll see, overwriting the Render Methode prevent the execution of these
three methods.
If you got a Tag around your Control, then better overwrite these three or
one of these, if needed.
Otherwise inherit from Control and overwrite the Render Method.

Signature

Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET

Walter Wang [MSFT] - 24 Jul 2007 03:10 GMT
Hi Allan,

I agree with John and Peter here.

For some crash courses on developing ASP.NET custom server controls, you
may find following articles useful:

#Creating Controls
http://msdn2.microsoft.com/en-us/library/aa530687.aspx

Hope this helps.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.