Custom Control

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
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
 
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
 
I don't mess a lot with this stuff, but i *think* the AddAttribute goes
BEFORE the RenderBeginTag call...

Karl
 
Back
Top