adding an attribute to a htmltextwriter tag.

C

Chaprasi

Hi,

I am new to writing a control sorry if this question was answered.

I am writing a control where I override the RenderBeginTag, now in this
method I would like to create a DIV tag and add attributes to it.

writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.AddAttribute(HtmlTextWriterAttribute.Id, "div1");

when I view the source the DIV has no attributes ID in it, how can I
achieve this, I know I can write this

writer.WriteLine("<div id='div1'>");

Any thoughts or ideas ?

Thanks
Chaprasi
 
P

Peter Morris [Droopy eyes software]

MSDN says

" Overloaded. Adds the specified markup attribute and value to the opening
tag of the element that the HtmlTextWriter object creates with a subsequent
call to the RenderBeginTag method."

So I would guess those two lines need to be swapped!
 
C

Chaprasi

Thank you

that sure worked well.

writer.AddAttribute(HtmlTextWriterAttribute.Id, "div1");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.RenderEndTag();
 

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

Top