We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Build table in vb, send to client as html

codequest asked
Medium Priority
Last Modified: 2012-06-27
When a button is pushed on the page, JS in the page does a callback to the server.
At the server, the app builds a menu table and sends it back to the client.
JS then makes it visible and the user can click on it.

This all works fine.

However, I saw something that might make this easier to work on.

Right now I'm building the menu table in vb at the server by piecing together HTML strings.
I saw a piece of syntax at another post that looks like this.

Dim oTbl As New Table()
oTbl.Width = "650"

Relative newbie that I am, I'd never seen this before.   Now looking at it, I assume there are ways to add rows and cells and click events and the whole works.

My questions are:

Q1:  is that a valid assumption?  (that is, can I add rows, cells, content, click events using that type of syntax)
Q2:  is there a way to get the table thus created turned into a raw HTML string that I can send back to the client using my callback routines?

I appreciate that AJAX, ATLAS and submits are other ways to get the table to the page, but I'm using callbacks now and I have to send the raw html to the page.

Any help with this would be appreciated.


Watch Question

I would say yes to both of your qestions though i am unsure about the onclick events

this is what i was using to build a table

Dim sTable1 As String = "<table><tr>"
        sTable1 += "<td>Location</td>"
        sTable1 += "<td>Function</td>"
        sTable1 += "<td>Employees</td>"
        sTable1 += "<td>PCs</td>"
        sTable1 += "</tr>"
        Do While odr.Read
            sTable1 += "<tr>"
            sTable1 += "<td>" & odr("LocationName") & "</td>"
            sTable1 += "<td>" & odr("LocationFunction") & "</td>"
            sTable1 += "<td>" & odr("NumOfEmp") & "</td>"
            sTable1 += "<td>" & odr("NumOfPCs") & "</td>"
            sTable1 += "</tr>"
        sTable1 += "</table>"
        odr = Nothing


Thanks for the note.  I was actually looking for more info on the syntax like:

Dim oTbl As New Table()
oTbl.Width = "650"

where apparently "Table" is a class in vb.net that you can do things with.   Probably in msdn, now that I take a moment to think about it....  

ah, here it is....


but I'm still looking for an answer on getting the raw html from that table...
.Net Senior Developer
       Dim t As New HtmlControls.HtmlTable
        Dim r As New HtmlControls.HtmlTableRow
        Dim c As New HtmlControls.HtmlTableCell



Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


lem2802:  thanks for the input.  I think that confirms the use of the vb syntax to create the table.

The remaining question, and this is the critical piece....

>>> How can I get a String variable that represents the raw HTML for the entire table, after I've created the table it using HtmlControls classes and methods?

I need to get that string because I'm going to instantiate the table by sending that string to the page via a callback, not a postback.   That part all works fine, and I'd rather build the table in HtlmControls...but only if I can get the raw HTML that is created.

infact what u should do is add a table in the aspx page and set it to runat = server .. then u can access it in ur code-behind (vb) as a normal HTMLTable control and do all those things what u need .. i.e add a cell, row etc ..

aspx page ..
<table id=MyTable runat=server></table>

in vb file .. try this ..
MyTable.Rows.Add(New HtmlTableRow)
Okay i think people might be getting confused here...

lem2802 has shown exactly how to create tables using the HtmlTable option

When he has the line Me.Controls.Add(tb) it renders the table in html format to the page so if you are just looking for the exact html it will be on the page.

How are you calling this function?

To get the pure html string you can try t.InnerHtml
my suggestion .. there is no need to create a table dynamically, else u will need a placeholder to place it in .. or else specify all the parameters to position it .. it would be better to add the table (runat =server) in design time .. make it invisible .... do all the manipulation to the table in the server (as needed) when the user clicks on the button and also make the table visible ..

I agree with you Rejo, but it does depend on what the user requires.

I have a page which can have anything between 1 and 500 tables on it. The user gets to decide. This page is created using Ajax controls so I don't want to create 500 invisible tables on the page. I just have a seperate form that returns a table every time a new one is requested.

So it is very dependent on what the requirements are...
requirements ...
>>When a button is pushed on the page, JS in the page does a callback to the server.
At the server, the app builds a menu table and sends it back to the client.
JS then makes it visible and the user can click on it.


Thanks for the inputs.

The "menu table" is actually a set of three nested menus, the contents of which vary according to which custom html button in a customized gridview is pushed.  I'm using callbacks to reduce pageflashes, and building the table set at the server because I've got to check some other things at the server, and in order to reduce use of javascript (due to various preferences).  

As I said, this all works fine...in this question I was looking for a way of building the tables using easier syntax (which lem2802  answered above) ....AND extract the inner html, which Gavin has now suggested may work with


I'll try that out soon...and report back how it works.



Oh, Gavin, in response to your question, "how am I calling this function"...it gets called through a "callback router" which interprets various callback messages from the client, and sends them to various locations in the server custom class code.   Eventually, a routine says "build the html for the menu table set", and the resulting html string is placed in the callback return "outbox" string.    The function calls return back through the stack, and then the callback "return to client" routine executes, sending the html string to the client.  There I pick it up on the return routine at the client, send it to a router there, and eventually pass it the innerHTML of a <div>.

So in the "build the html for the menu table set" routine I'd like to try the vb HtmlControls approach rather than fool with all the raw HTML strings, which are a little tricky to maintain.


Msdn:   No joy:

HtmlTable.InnerHtml Property
Do not read from or assign a value to this property. Otherwise, a System.NotSupportedException exception is thrown. This property is inherited from the HtmlContainerControl class and is not applicable to the HtmlTable class.

I fooled around with the HtmlControls objects in VB a little, but didn't see any paths to get the innerHTML from a table (like put the table inside a cell).   Unless anyone has other suggestions, I would say the answer to the initial inquiry is

A)  yes you can build tables using HtmlControls, etc.
B)  no, you can't convert them to raw HTML strings (except, of course, somewhere between standard vb and the bare metal, there's always a way!)

Any other thoughts?
Hmm.... Nope :)

Seriously the way I use my AJAX is that I place the table onto a completely blank page and then just read the returned html of that page.

The other way I have used is Javascript but I don't think that will work for this solution.

Maybe for your circumstances the original way you are using it is best. The only thing I would recommend is use the StringBuilder class instead of plain string.


Ok, thanks for the idea.  I'll check out string builder.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.