codequest
asked on
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!
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!
ASKER
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...
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...
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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.
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)
aspx page ..
<table id=MyTable runat=server></table>
in vb file .. try this ..
MyTable.Rows.Add(New HtmlTableRow)
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
Rejo
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...
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.
>>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.
ASKER
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!
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!
ASKER
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.
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.
ASKER
Msdn: No joy:
HtmlTable.InnerHtml Property
Remarks
Caution
Do not read from or assign a value to this property. Otherwise, a System.NotSupportedExcepti on 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?
HtmlTable.InnerHtml Property
Remarks
Caution
Do not read from or assign a value to this property. Otherwise, a System.NotSupportedExcepti
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.
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.
ASKER
Ok, thanks for the idea. I'll check out string builder.
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()