473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

When to override Render

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
Jul 23 '07 #1
3 2878
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
"Allan Ebdrup" <eb****@noemail.noemailwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
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

Jul 23 '07 #2
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.

--
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

Jul 23 '07 #3
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 (wa****@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.

Jul 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: threecrans | last post by:
If you create a new server control, and override the Render method with the following code: protected override void Render(HtmlTextWriter output) { // <TABLE id="mytable">...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
3
by: sonic | last post by:
Hi, displaying information on a page as MS Word document seems to be as simple as: //OnLoad Response.ContentType = "application/msword"; Response.Write ( MyContentString ); (this assuming...
3
by: John Hughes | last post by:
I'm trying to add a user control to a form via the pages render method and I get the following error : "Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server" ...
0
by: milmus tender | last post by:
Hi, we have some customized EditorParts, which inherits from a DefaultEditor. This DefaultEditorPart inherits from the standard EditorPart-Class. In this DefaultEditorPart we override the...
0
by: John | last post by:
I'm trying to override the page's render method, and capture the result for processing, eg: protected override void Render(HtmlTextWriter writer) { //base.Render(writer); StringBuilder...
13
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
5
by: =?Utf-8?B?QWRhciBXZXNsZXk=?= | last post by:
Hi All, I have a GridView inside the EditItemTemplate of a FormView. Both FormView and GridView are data bound using an ObjectDataSource. When the FormView's ObjectDataSource object has a...
2
by: Jason | last post by:
Hi all, I hope this doesn't sound like a lame question, but I want to override Gridview.Render so I can strip out ALL styling elements and use CSS for my styling. I am pretty sure I can figure it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.