How to Access HTML Controls from code behind ?

V

viveklinux

Hi ,

I have a table which needs to be populated at runtime. Is there a way
to do this without using a server side control like repeater or
datagrid ? How can an HTML control be accessed in code behind ?

Thanks in advance ..
 
M

Michael Nemtsev

Hello vivekian,

how your server may know about client controls?
you need to use either server controls or use XMLHttpRequest to get data
in runtime and fill your client

v> Hi ,
v>
v> I have a table which needs to be populated at runtime. Is there a way
v> to do this without using a server side control like repeater or
v> datagrid ? How can an HTML control be accessed in code behind ?
v>
v> Thanks in advance ..
v>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
C

Cor Ligthert [MVP]

For most you can just add runat=server and than they go.

By instance the input box or the Iframe.

I hope this helps,

Cor
 
G

google

Hi

There are two things you have to do.

(1) Edit the HTML code to include the attribute runat="server" in the
opening tag of the HTML control. For example for a table it might be:

<TABLE id="Table1" ...(other attributes) ... runat="server">

(2) Then you need to include the namespace "System.Web.UI.HtmlControls"
in the code behind (e.g. in VB the directive Imports
System.Web.UI.HtmlControls).

If you are using Visual Studio then you will find that it will become
available in auto-complete under the identifier (in the example above)
Table1.

With that you will be able to program it's behaviour in a very similar
manner to web Server controls.

Hope that helps

Phil Hall
 
P

Phil H

Hi

There are two options here.

One is to use a server control of type "Table" i.e.
System.Web.UI.WebControls.Table which you can construct in code by
creating objects of type TableRow and TableCell. To put content in the
cells use the method "Controls.Add(x)" for the TableCell object where x
is any other type of visual control (e.g. a label)

The other way is to add the attribute runat="server" to an HTML table
tag
e.g. <TABLE id="Table1" ... runat="server">.

Also make sure that it has an ID attrubute, i.e. an attribute like
id="Table1". Then include the namespace System.Web.UI.HtmlControls
(e.g. in VB; Imports System.Web.UI.HtmlControls)

Having done that populate the table using the InnerHtml property for
cells, e.g. in VB:

Table1.rows(x).cells(y).InnerHtml = "<p>Hello World</p>"

where x, y are zero referenced integers

Hope that helps
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top