using .ascx file to create server control

S

Steve Richter

I like the idea of being able to place server controls in an assembly
and use them in all of my web applications. On the other hand I like
the ease of using an .ascx file when I write user controls.

so far in my practice drills to learn server controls I have done a lot
of rendering calls to write HTML to the HtmlTextWriter object:

protected override void Render( HtmlTextWriter InWriter )
{
InWriter.AddStyleAttribute( "font-family", "Verdana,Arial" ) ;
InWriter.RenderBeginTag( "table" ) ;
InWriter.RenderEndTag( ) ;
}

which is a lot of work. When I write a user control I can use the
..ascx file to build the control from Web Controls and other user
controls.

Should I keep on reading up on server controls? Will I learn how to
write a server control in a similar fashion to writing a user control?

thanks,

-Steve
 
K

Karl Seguin

Steve:
You've pretty much summed up the limitation and advantages of both methods.
My suggestion to those wishing to learn how to utilize custom server
controls has always been to start slowly and build up on your knowledge.
For example, I often say that it's important to start with simple custom
server controls which inherit existing server controls (say a label you
always want a colon appended to) and move forward.

Yes, you should continue learning about them as they provide tremendous
flexibility. There are plenty of online tutorials and examples as well to
help you. I've also used
http://www.amazon.com/exec/obidos/tg/detail/-/0735615829/103-0635232-3339822?v=glance
though I'm not sure I recommend it. In my opinion the book is extremely
hard to follow and often makes custom server controls an even more
complicated thing.

Finally, an alternative to using Render is to use the CreateControl method
which would let you add your table programatically. Table table = new
HtmlTable(); .... however there are both downsides and upsides to this
alternative...

Cheers,
Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top