How do YOU build your server controls? Using writer to output html or using controls?

What's the preferred way of overriding Render when building server controls?  Is it better to use the writer to output the html with RenderBeginTag and etc, or is it better to just create a table/panel control and add controls to it and render the table/panel control?

For example, let say I want to create a server control to output the following in html
<table>
   <tr>
      <td>
         Welcome
      </td>
      <td>
         Dynamic Text
      </td>
   </tr>
</table>

First way with writer

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

'Assume this is already created with some text that's passed in via a Property

Dim Label As New Label

Label.Text = "Dynamic Text"

writer.RenderBeginTag(HtmlTextWriterTag.Table)

writer.RenderBeginTag(HtmlTextWriterTag.Tr)

writer.RenderBeginTag(HtmlTextWriterTag.Td)

writer.Write("Welcome")

writer.RenderEndTag()

writer.RenderBeginTag(HtmlTextWriterTag.Td)

Label.RenderControl(writer)

writer.RenderEndTag()

writer.RenderEndTag()

writer.RenderEndTag()

End Sub

Second way with control

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

'Assume this is already created with some text that's passed in via a Property

Dim Label As New Label

Label.Text = "Dynamic Text"

Dim Table As New Table

Dim Row As New TableRow

Dim WelcomeCell As New TableCell

WelcomeCell.Controls.Add(new LiteralControl("Welcome")

Dim DynamicCell As New TableCell

DynamicCell.Controls.Add(Label)

Row.Cells.Add(WelcomeCell)

Row.Cells.Add(DynamicCell)

Table.Rows.Add(Row)

Table.RenderControl(writer)

End Sub

0
Ninjamyst
10/26/2005 3:55:07 PM
asp.net.hosting-open-forum 4216 articles. 0 followers. Follow

3 Replies
1030 Views

Similar Articles

[PageSpeed] 12
Get it on Google Play
Get it on Apple App Store

It depends greatly on need to balance between reusability (reusing existing controls) and performance metrics. Using rendering is efficient, however using child controls can greatly simplify development and enable you to build the thing in a few minutes.

So, they both are correct ways and there's no easy answer. I keep the line so that I render all the stuff for which I don't need complex server-side functionality (or which is found in reusable form). But if I need child controls, I use them and won't try to push the render approach for too long if it takes too much time to implement.
Thanks,

Teemu Keiski
Finland, EU
0
joteke
10/26/2005 5:17:00 PM
 joteke wrote:
It depends greatly on need to balance between reusability (reusing existing controls) and performance metrics. Using rendering is efficient, however using child controls can greatly simplify development and enable you to build the thing in a few minutes.

So, they both are correct ways and there's no easy answer. I keep the line so that I render all the stuff for which I don't need complex server-side functionality (or which is found in reusable form). But if I need child controls, I use them and won't try to push the render approach for too long if it takes too much time to implement.


Thanks for your response.  I am used to rendering but my coworkers rather use child controls because it is easier to change and expand.  I do find creating new controls rather inefficient.  I just wanted to know what everyone's opinion was.  Thanks!
0
Ninjamyst
10/26/2005 5:47:33 PM
I agree with your co-workers. The cost of doing child controls vs. complete rendering is so small, it's not really worth comparing it. Besides, even if it did cost 2% between the two, development can increase ten-fold. And if your company is always fighting for those deadlines, especially if you are a consultancy company, you will try to save as much time for testing of deliverables. And when it comes to evolving the code... complete relief I tell you.

-- Justin Lovell
0
master4eva
10/29/2005 8:22:51 PM
Reply:

Similar Artilces:

Modifing javascript to use server controls instead of using html controls
Hi, I use a Javascript to create a textbox that converts English to Hindi text. I am using it in my aspx pages. I use another javascript to access the Text of this HTML textbox.  Everything is fine when I use Single TextBox on a page. But the complexities go out of my control when i need to use 5 such textboxes on the same aspx page. Moreover I encounter issues of ID of ASP.NET controls that get changed as there are ContentPlaceHolders, TabPanels etc. I don't know the javascript things so deeply that I can comprehend the code that generates the custom Textbox. Now I ne...

What control do I use (or do I not use a control at all...)
Okay so here's the story so far. I am making a blog to be incorporated into a website. Well, I'm doing the blog from scratch. I'm using MySQL to source all the data via MySQL .NET/Connector. Now while developing the script, I used DataReader and Response.Write to show the blog topics. Now that it has come to put it under a design (I'm using a Master Page for that), I've hit the problem. Response.Write shows all the topics before any of the design elements could be incorporated. So that (more or less) is out of question. So next I looked into the data presentation controls. I looked up GridVi...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

How to access dynamically Html controls (client side controls) using C# server side scripts
Folks,I have problem try to to access dynamically Html controls (client side controls) using C# server side scripts. Please give me helps.     The error is as follows Exception Details: System.InvalidCastException: Specified cast is not valid.Source Error: Line 79: { Line 80: Control c = Page.FindControl("ddlTC" + i); Line 81: ((DropDownList)c).DataSource = mdt; Line 82: ((DropDownList)c).DataTextField = "ClassID"; Line 83: ((DropDownList)c).DataValueField = "Course"; My aspx page source codes: ...<...

When to use web control and Html control
I am designing a web application in which onclick a form becomes visible containing set of text boxes and other fields. How shoud I design it. I am not able to figure out difference between web form controls and html controls. Shrinivas...

Who uses Web Controls/HTML Controls?
I'm currently making the migration from ColdFusion to asp.net and I have a few questions. 1. Does anybody really use the Web/HTML Controls? CF has something similar <cfform> but I never use it because I'm a believer in separating html from application logic/control. And I like being in control of what goes on in my apps. However, I find the Web/HTML Controls interesting. 2. Is there a standard framework that people use to organize their code? I like using MVC (Model, View, Controller) to create true N-tier applications. Just wondering what others use. 3. Is anybody using Flash...

Using Data Controls Without Using ObjectDataSource Control
Hi, I've been looking on the Internet for a tutorial that would show me how to use the data conrols (FormView, GridView etc) without using an ObjectDataSource (or any other data source control).  The reason is that I want to use a formview and gridview from within another formview control to create a single form  that would allow me to insert, update and delete an order and its order details at the same time. I thought that this could be achieved by having a DataSet containing two DataTable objects in the code-behind with the Order DataTable containing one row to repres...

Using a server control in the rendering a custom control
Hi. I have a custom control that overrides the Render method to draw itself.  Is it possible to use a server control (asp:Image, wwHoverPanel, etc.) inside such a custom control or would I have to rewrite my custom control as a composite control? I'd like to do something something like:protected override void Render(HtmlTextWriter w) { w.RenderBeginTag(HtmlTextWriterTag.Table); w.RenderBeginTag(HtmlTextWriterTag.Tr) w.RenderBeginTag(HtmlTextWriterTag.Td) // somehow place asp:Label here w.RenderEndTag(); // column w.RenderEndTag(); // row ...

Need a server control that uses the calendar control
I want to develop a server control that uses the calendar control.  This new control will have one string property passed in from the outside.  The control will use a SQL stored proc to gather data used in the page render section of the calendar control.  The property will be passed to the stored proc.  In case you're wondering, I need this because I program in VB and an app that I need to use this in is written in C#.  Once I have the control, I can put it in the app and use it as desired.  I have the working code in a web project, I just need to know how...

Using a user control in a custom server control.
I've created a custom server control and am trying to add a user control to the rendering of the server control.  Is this possible?  If so, hints as to how this is done would be GREATLY appreciated!  Thanks in advance for considering an answer to this question. Wendi Use the LoadControl method. For example:   Controls.Add(LoadControl("~/controls/login.ascx"))Steven BeyRecursion: see Recursion My server control renders a table with x number of rows.  I want to add a user control to each row of the table, last column.  I do not know how ...

Using server controls or user controls in FrontPage
I have a frontpage website with shared borders. Can I use a server control (or user control) in FrontPage as the top border? Or could I embed the control in the top border? My dad mentioned something like this scenerio to me and of course I did not have a solution. He finally gave up on FrontPage and converted the entire thing to ASP.Net... as far as both of us were concerned by the end of the day - you cannot mix two server technologies together with little to medium ease. :: I have a frontpage website with shared borders. If you mean frames, then the above does not apply really b...

Using AJAX control Externders with Html controls
How does the Control Extenders from AJAX Tool kit work with Html controls? Recently I tried to convert one of my ASP.NET 2.0 application to AJAX. Every things seems to be working fine. :) Unfortunatly our developers used HtmlInput Control instead of asp:TextBox. When I tried to the use the MaskedEditExtender control to work with HtmlInput control I'm getting a run time error. :( Here is the error message: "Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputText' to type 'System.Web.UI.WebControls.TextBox'." Does it mean that AJAX tool kit onl...

is it possible to use loginstatus control without using login control?
 Hi friendspls let me clear in this.is it possible to use loginstatus control without using login control?thanks in advance          Yes, if you write your own login control that plugs in using asp.net authentication via the provider model then the login status will still work fine.You can set up custom providers in web.config.  thanks to reply. can u give me a sample code?  Yeah for custom providers in web.config its pretty simple, but the rolling your own is a complex task. Do you already have a database or some reason for...

How do I pass other HTML control in HTML control's click event using Javascript ?
Hello friends, Please give any idea for  how do I pass HTML control to Javascript code.  exam given below.. ------------------------------------------------------------------------------------------------------------------------<script>function SwitchTLStateTreeList1($nodeValue,$imgBtn){  $mode = 'table-row';  if ($imgBtn.src.search(/icon_collapse/) != -1)  {    $imgBtn.src = $imgBtn.src.replace(/collapse/g,'expand');    $mode = 'none';  }  else if ($imgBtn.src.search(/icon_expand/) != -1) &nb...

Web resources about - How do YOU build your server controls? Using writer to output html or using controls? - asp.net.hosting-open-forum

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

The US needs gun control to protect children like my grandson, killed at Sandy Hook
Motives do not matter to the dead. They don't matter much to survivors, either.

The little box that controls half your home’s energy use
(credit: Nest Labs) A thermostat can be such a simple device—so dumb a device if we’re feeling 21 st Century snobby—that a strip of metal coiled ...

How to perform Jedi mind control tricks using neuroscience
... looking for..." With those words, Obi Wan Kenobi inspired a generation of nerdy young men to try their hands at performing Jedi mind control ...

Sandy Hook parents assess victories, defeats in gun control mission
CBS News Sandy Hook parents assess victories, defeats in gun control mission CBS News NEWTOWN, Conn. Three years ago on Monday, a gunman opened ...

Apple is about to take even more control
... be about to get tough for some Apple partners as the company invests in top secret display technology development labs and increases its control ...

Hilarious: ‘Burglars For Gun Control’ Sums Up The Left’s Entire Argument
'As long as law abiding citizens have guns, it's that much harder for burglars like me to do my job.'

Bart & Fleming: Don’t Come To Year-End Movies To Get Laid; Time For Movies About Gun Control Debate?
Peter Bart and Mike Fleming Jr. worked together for two decades at Daily Variety . In this weekly Sunday column, two old friends get together ...

Halo 5 is getting advanced control options
... is a good day. There's more to next week's update for Halo 5: Guardians than Forge mode, maps, and REQs. The game is also expanding its control ...

Microsoft Band 2 gets new music controls and activity reminders
... has revealed a few fresh features for the device, designed to make it smarter and more functional. For starters, there are new music controls, ...

Resources last updated: 12/15/2015 5:22:44 PM