Build table in vb, send to client as html

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.

Thanks!

LVL 2
codequestAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ptleitchCommented:
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>"
        Loop
        sTable1 += "</table>"
        odr = Nothing
        GC.Collect()
0
codequestAuthor Commented:
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....

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolstableclasstopic.asp

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

        r.Cells.Add(c)
        t.Rows.Add(r)

        Me.Controls.Add(t)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

codequestAuthor Commented:
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.

0
RejojohnyCommented:
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)
0
GavinMannionCommented:
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
0
RejojohnyCommented:
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 ..

Rejo
0
GavinMannionCommented:
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...
0
RejojohnyCommented:
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.
0
codequestAuthor Commented:
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

t.InnerHtml

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

Grazie!
0
codequestAuthor Commented:
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.
0
codequestAuthor Commented:
Msdn:   No joy:

HtmlTable.InnerHtml Property
 
Remarks
Caution  
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?
 
0
GavinMannionCommented:
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.
0
codequestAuthor Commented:
Ok, thanks for the idea.  I'll check out string builder.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.