<DIV> addding text from code behind.

G

Gregory

Hi all.

A quick question.

In normal XHTML pages, you can put text inside of a <div> element, and
all goes well.
Essentially, im trying to port over some XHTML stuff into asp.net, but
add in dynamic generation, blah, blah, blah.

So i need to be able to add text to a div from the code behind. Any way
of doing this? Labels dont work for me, the divs have been tested on
all the required browsers, and every thing works just fine display
wise.

Any ideas?

Thanks
 
C

Chris Botha

The div must be runat=server, then in the code-behind use
MyDiv.InnerText = ...
or
MyDiv.InnerHtml = ...
 
G

Gregory

okay, but im Declaring the object as

Dim obj As New WebControls.WebControl(HtmlTextWriterTag.Div)


i assume thats the wrong thing, as it doenst have the InnerText or
InnerHtml properties.

what should i Declare this object as?

Thanks
Greg
 
C

Chris Botha

Give this a shot
Dim theDiv As HtmlGenericControl = New HtmlGenericControl("DIV")
 
G

Gregory

okay, that works, many thanks.

....but theres anouther issue there.

You cant bind CSSClasses on that object. I can set the style
collection, but that kinda sucks, and is a bit yuck. Is there a way to
put a CSSClass on that object?

Thanks
Greg
 
C

Chris Botha

Sorry, my knowledge of CSS is to have a <link ...> in the header of the page
and that's about it.
Have a look at the MyDiv.Attributes property or MyDiv.Attributes.CssStyle
property though.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top