innerHTML not working

S

sling blade

Hello,

I am trying to get the innerHTML method to work but I am not getting
any output.

Here is my code:

(Code behind)
Dim display as New HtmlGenericControl
Dim strResultsHolder As String

strResultsHolder = "<table><tr><td>Hello World</td></tr></table>"
display.InnerHtml = strResultsHolder

(The HTML section of my form)

<div id=display runat=server> </div>

(end HTML section)

Can someone please tell me if this is correct? I am wondering how I
specifically reference the div id (display).

I have given it a HtmlGenericControl datatype in the code behind but is
that good enough to point it to the div id of the same name in the
form?

In all of the samples I can google not one has specifically referenced
the HtmlGenerciControl class in the code. They all say to do it but
don't actually show it being done.

Can someone say if this is correct or how to do it?

Thanks
 
S

Steve C. Orr [MVP, MCSD]

Remove "New"
Don't instantiate the control.
Let ASP.NET instantiate it and match it with the control of the same name in
your HTML.
 
S

sling blade

I tried that and I get this error
Object reference not set to an instance of an object.

at this text is highlighted in red:
display.InnerHtml = strResultsHolder


When I instantiate display with the New keyword I don't get the error
but still no table.

Any ideas?
 
S

Steve C. Orr [MVP, MCSD]

Where are you declaring it?
It should be declared as "protected" at the top of your class along with the
other standard controls such as labels, buttons, etc.
 
K

Karl Seguin

You also need to declare it as "protected" instead of "dim"

so

protected display as HtmlControl ought to do the tric;

the aspx page inherits from the codebehind and "protected" allows
sub-classes to access the property.. I believe that "dim" does private by
default...which is too limiting in this case

Karl
 
S

sling blade

Great! That did it. And thanks for the explanation too (that was my
next question).
 
S

sling blade

By the way Karl the link to My ASP.Net tutorials doesn't seem to be
working (at least I can't get to it right now anyway)
 
P

Patrick Olurotimi Ige

Yeah u have to declare it as:-

Protected WithEvents display As
System.Web.UI.HtmlControls.HtmlGenericControl

Patrick
 

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,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top