|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Render web custom controlHi, 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 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. Show quoteHide quote "Peter Kirk" <p*@alpha-solutions.dk> wrote in message news:uF3Dy4WFHHA.1240@TK2MSFTNGP03.phx.gbl... > 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 >
client-side code
Populate DropDownList w/ GridView Header Text gridview column alignment How to add DataSource to a TreeView programmatically Dropdownlist selected value Self populating UserControl Self populating UserControl Dropdown in webpart lost its state after postback Urgent: NullReferenceException on RenderControl method of TreeView Set NextPageText and PreviousPageText Runtime |
|||||||||||||||||||||||