Custom Control

S

shapper

Hello,

I have been creating custom controls based on Asp.Net 2.0 controls
using CreateChildControls.

When I look at the HTML source it looks like Asp.Net wraps all the
child controls with a span tag.

Why?
And can I use a div tag as a wrapper?

Thanks,
Miguel
 
K

Karl Seguin

I believe you want to look at overriding the RenderBeginTag and RenderEndTag
methods...

public override void RenderBeginTag(HtmlTextWriter writer)
{
writer.Write("<div>");
}

or something..

Karl
 
S

shapper

Karl said:
I believe you want to look at overriding the RenderBeginTag and RenderEndTag
methods...

public override void RenderBeginTag(HtmlTextWriter writer)
{
writer.Write("<div>");
}

Hi,

That is exactly what I wanted. However I am having a problem. I am
using the following code:

' RenderBeginTag
Public Overloads Overrides Sub RenderBeginTag(ByVal writer As
HtmlTextWriter)

' Write writer content
writer.RenderBeginTag(HtmlTextWriterTag.Div)

' Add writer attributes
writer.AddAttribute("id", Me.ID)
writer.AddAttribute("class", Me.CssClass)
writer.AddAttribute("width", Me.Width.ToString)

End Sub ' RenderBeginTag

What is strange is that the attributes are not being applied to this
<div> but to a <div> which is generated by a Panel which being added as
a child control of my custom control.

What am I doing wrong?

And by the way, why does a custom control uses <span> as default render
wrapper tag?
This is quite strange as Panel is rendered as <div>. So if I use a
Panel in a custom control which might be quite normal I will have
problems as a <div> can't be placed inside a <span>

Check: http://www.cs.tut.fi/~jkorpela/html/nesting.html

Thanks,
Miguel
 
K

Karl Seguin

I don't mess a lot with this stuff, but i *think* the AddAttribute goes
BEFORE the RenderBeginTag call...

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top