Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Render web custom control

Reply
Thread Tools

Render web custom control

 
 
Peter Kirk
Guest
Posts: n/a
 
      12-01-2006
Hi, if I am writing a web custom control, do I override the Render method or
the RenderControl or the RenderContents method - and what is the difference?

Thanks,
Peter


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      12-02-2006
Hi,

basically the chain goes so that at render stage, Page calls into
RenderControl of your control, which again directs this call to Render and
that again to again RenderContents. Does your control have RenderContents
depends on if it derives directly from System.Web.UI.WebControls.WebControl.

Essentially the main Render methods are:

System.Web.UI.Control
=================

-RenderControl
-Render
-RenderChildren

They are implemented so that RenderControl calls Render if control is
visible. Render then calls directly RenderChildren which calls RenderCotrol
for every child control

System.Web.UI.WebControl
====================

-derives from System.Web.UI.Control so has inherited Control's rendering
methods

Adds following rendering methods to the implementation:

-AddAttributesToRender
-RenderBeginTag
-RenderContents
-RenderEndTag

And what's important, WebControl overrides Render method pretty much like
this

protected override void Render(HtmlTextWriter writer)
{
RenderBeginTag(writer);
RenderContents(writer);
RenderEndTag(writer);
}

where RenderBeginTag calls AddAttributesToRender and writes out the begin
tag by using given HtmlTextWriter. And WebControl's RenderContents calls to
base.Render which essentially of course calls Control's Render methods
causing child controls to be rendered.

So what's this all about? It's tight set of predefined rendering flow in
which you can override everything or just one small snippet of it.
Therefore what you want to render is the driving reason to think what should
be overridden and when. Difference with the methods you asked is pretty much
that with RenderControl you make the control to render at any time as
RenderControl is also a public method. Render and RenderContents are
protected methods only callable in the class or in derived classes. Render
is meant to control the entire rendering flow while RenderContents is meant
to render markup between control's begin and end tags.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke



"Peter Kirk" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi, if I am writing a web custom control, do I override the Render method
> or
> the RenderControl or the RenderContents method - and what is the
> difference?
>
> Thanks,
> Peter
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to render a custom web control DalePres ASP .Net Web Controls 2 06-26-2004 01:22 PM
Page.Render do not render complete page Lau Lei Cheong ASP .Net 1 05-15-2004 04:10 AM
Web Custom Control Render Problem Billy Boy ASP .Net Web Controls 7 03-06-2004 04:01 PM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com ASP .Net Building Controls 1 07-02-2003 08:05 AM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com ASP .Net 0 07-01-2003 09:26 PM



Advertisments