Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Build table in vb, send to client as html

Posted on 2006-03-28
14
Medium Priority
?
530 Views
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.

Thanks!

0
Comment
Question by:codequest
  • 6
  • 3
  • 3
  • +2
14 Comments
 
LVL 3

Expert Comment

by:ptleitch
ID: 16314045
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
 
LVL 2

Author Comment

by:codequest
ID: 16314354
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
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 1000 total points
ID: 16314424
       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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:codequest
ID: 16315548
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16318552
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
 
LVL 15

Assisted Solution

by:GavinMannion
GavinMannion earned 1000 total points
ID: 16319098
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16319329
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
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16319397
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16319414
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
 
LVL 2

Author Comment

by:codequest
ID: 16329164
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
 
LVL 2

Author Comment

by:codequest
ID: 16329218
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
 
LVL 2

Author Comment

by:codequest
ID: 16364029
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
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16390081
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
 
LVL 2

Author Comment

by:codequest
ID: 16395114
Ok, thanks for the idea.  I'll check out string builder.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question