By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,953 Members | 1,547 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,953 IT Pros & Developers. It's quick & easy.

Generating HTML in a web service

P: n/a
Perhaps I have missed something but what I would like to do is have a more
"controlled" method of generating HTML from a web service.

I can create items using HtmlTable, HtmlTableRow, and HtmlTableCell but is
there a quick method once the table has been built to get the HTML, put it
in a string for return the browser call for the web service?

I notice that HtmlTable does not support InnerHtml so that is not doable.

Ideas??

Thanks
Lloyd Sheen

Jul 3 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Lloyd Sheen" <a@b.cwrote in message
news:E1**********************************@microsof t.com...
Perhaps I have missed something but what I would like to do is have a more
"controlled" method of generating HTML from a web service.
What technique are you using now for generating HTML from a web service?

The usual way to do it is to have the web service return data, then to have
an ASP.NET page bind the data to controls which will produce the HTML.
--
John Saunders [MVP]

Jul 3 '07 #2

P: n/a

"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:uv**************@TK2MSFTNGP03.phx.gbl...
"Lloyd Sheen" <a@b.cwrote in message
news:E1**********************************@microsof t.com...
>Perhaps I have missed something but what I would like to do is have a
more "controlled" method of generating HTML from a web service.

What technique are you using now for generating HTML from a web service?

The usual way to do it is to have the web service return data, then to
have an ASP.NET page bind the data to controls which will produce the
HTML.
--
John Saunders [MVP]
At present I am just creating strings of the output HTML. I was looking for
a structured method using dotnet objects. Something like (just typed in so
most likely has errors)

<WebMethod()_
Public Function JustATest(ByVal Name As String) As String
Dim s As String = String.Empty

Dim tab As New HtmlTable
Dim r1 As New HtmlTableRow()
Dim c1 As New HtmlTableCell()
c1.InnerText = "Col1"
Dim c2 As New HtmlTableCell()
c2.InnerText = Name
r1.Cells.Add(c1)
r1.Cells.Add(c2)
tab.Rows.Add(r1)

dim s as string=string.empty
s=tab.??????
return s
End Function
????? would be a method name which would then issue the HTML to represent
the table and its contents.

Lloyd Sheen
Jul 3 '07 #3

P: n/a
This post shows how you can render the content of servercontrols to a string
using the RenderControl method.

http://petesbloggerama.blogspot.com/...ntrols-to.html

What you describe is really kind of a non-standard approach, but if that's
what you want to do, it should help.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"Lloyd Sheen" wrote:
>
"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:uv**************@TK2MSFTNGP03.phx.gbl...
"Lloyd Sheen" <a@b.cwrote in message
news:E1**********************************@microsof t.com...
Perhaps I have missed something but what I would like to do is have a
more "controlled" method of generating HTML from a web service.
What technique are you using now for generating HTML from a web service?

The usual way to do it is to have the web service return data, then to
have an ASP.NET page bind the data to controls which will produce the
HTML.
--
John Saunders [MVP]

At present I am just creating strings of the output HTML. I was looking for
a structured method using dotnet objects. Something like (just typed in so
most likely has errors)

<WebMethod()_
Public Function JustATest(ByVal Name As String) As String
Dim s As String = String.Empty

Dim tab As New HtmlTable
Dim r1 As New HtmlTableRow()
Dim c1 As New HtmlTableCell()
c1.InnerText = "Col1"
Dim c2 As New HtmlTableCell()
c2.InnerText = Name
r1.Cells.Add(c1)
r1.Cells.Add(c2)
tab.Rows.Add(r1)

dim s as string=string.empty
s=tab.??????
return s
End Function
????? would be a method name which would then issue the HTML to represent
the table and its contents.

Lloyd Sheen
Jul 3 '07 #4

P: n/a
"Lloyd Sheen" <a@b.cwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>
"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:uv**************@TK2MSFTNGP03.phx.gbl...
>"Lloyd Sheen" <a@b.cwrote in message
news:E1**********************************@microso ft.com...
>>Perhaps I have missed something but what I would like to do is have a
more "controlled" method of generating HTML from a web service.

What technique are you using now for generating HTML from a web service?

The usual way to do it is to have the web service return data, then to
have an ASP.NET page bind the data to controls which will produce the
HTML.
--
John Saunders [MVP]

At present I am just creating strings of the output HTML. I was looking
for a structured method using dotnet objects. Something like (just typed
in so most likely has errors)

<WebMethod()_
Public Function JustATest(ByVal Name As String) As String
Dim s As String = String.Empty

Dim tab As New HtmlTable
Dim r1 As New HtmlTableRow()
Dim c1 As New HtmlTableCell()
c1.InnerText = "Col1"
Dim c2 As New HtmlTableCell()
c2.InnerText = Name
r1.Cells.Add(c1)
r1.Cells.Add(c2)
tab.Rows.Add(r1)

dim s as string=string.empty
s=tab.??????
return s
End Function
????? would be a method name which would then issue the HTML to represent
the table and its contents.
Well, as I said earlier, the usual way is to separate the presentation
(HTML) from the data and business logic (the web service). That's why people
usually use ASP.NET for this purpose.
--
John Saunders [MVP]

Jul 3 '07 #5

P: n/a

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:BA**********************************@microsof t.com...
This post shows how you can render the content of servercontrols to a
string
using the RenderControl method.

http://petesbloggerama.blogspot.com/...ntrols-to.html

What you describe is really kind of a non-standard approach, but if that's
what you want to do, it should help.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"Lloyd Sheen" wrote:
>>
"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:uv**************@TK2MSFTNGP03.phx.gbl...
"Lloyd Sheen" <a@b.cwrote in message
news:E1**********************************@microsof t.com...
Perhaps I have missed something but what I would like to do is have a
more "controlled" method of generating HTML from a web service.

What technique are you using now for generating HTML from a web
service?

The usual way to do it is to have the web service return data, then to
have an ASP.NET page bind the data to controls which will produce the
HTML.
--
John Saunders [MVP]

At present I am just creating strings of the output HTML. I was looking
for
a structured method using dotnet objects. Something like (just typed in
so
most likely has errors)

<WebMethod()_
Public Function JustATest(ByVal Name As String) As String
Dim s As String = String.Empty

Dim tab As New HtmlTable
Dim r1 As New HtmlTableRow()
Dim c1 As New HtmlTableCell()
c1.InnerText = "Col1"
Dim c2 As New HtmlTableCell()
c2.InnerText = Name
r1.Cells.Add(c1)
r1.Cells.Add(c2)
tab.Rows.Add(r1)

dim s as string=string.empty
s=tab.??????
return s
End Function
????? would be a method name which would then issue the HTML to represent
the table and its contents.

Lloyd Sheen
Thanks Peter, your method worked great. I just put it to a memory stream to
extract the HTML. I am using AJAX to call the webservice directly and then
populate a DIV with the output without having to do things like send
viewstate and whatever. I know what needs to be sent and this method is
much faster than a postback.

Thanks again this will stay in my bag of tricks.
Lloyd Sheen

Jul 3 '07 #6

P: n/a
you can always make use of RenderControl method to get the html:

' first create a memory stream to hold the output
Dim ms As New System.IO.MemoryStream
' now open HTML Text Writer
Dim writer As New System.Web.UI.HtmlTextWriter(New System.IO.StreamWriter(ms))
writer.BeginRender()
myHtmlTableControl.RenderControl(writer)
writer.EndRender()
writer.Flush()
' now reposition stream to the start
ms.Position = 0
Dim sr As New System.IO.StreamReader(ms)
Dim html As String = sr.ReadToEnd()
"Lloyd Sheen" wrote:
Perhaps I have missed something but what I would like to do is have a more
"controlled" method of generating HTML from a web service.

I can create items using HtmlTable, HtmlTableRow, and HtmlTableCell but is
there a quick method once the table has been built to get the HTML, put it
in a string for return the browser call for the web service?

I notice that HtmlTable does not support InnerHtml so that is not doable.

Ideas??

Thanks
Lloyd Sheen
Jul 4 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.