Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Generating HTML in a web service

Reply
Thread Tools

Generating HTML in a web service

 
 
Lloyd Sheen
Guest
Posts: n/a
 
      07-03-2007
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

 
Reply With Quote
 
 
 
 
John Saunders [MVP]
Guest
Posts: n/a
 
      07-03-2007
"Lloyd Sheen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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]

 
Reply With Quote
 
 
 
 
Lloyd Sheen
Guest
Posts: n/a
 
      07-03-2007

"John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
news:(E-Mail Removed)...
> "Lloyd Sheen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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


 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      07-03-2007
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.com> wrote in message
> news:(E-Mail Removed)...
> > "Lloyd Sheen" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> 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
>
>
>

 
Reply With Quote
 
John Saunders [MVP]
Guest
Posts: n/a
 
      07-03-2007
"Lloyd Sheen" <(E-Mail Removed)> wrote in message
news:%23MTZ$(E-Mail Removed)...
>
> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
> news:(E-Mail Removed)...
>> "Lloyd Sheen" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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]

 
Reply With Quote
 
Lloyd Sheen
Guest
Posts: n/a
 
      07-03-2007

"Peter Bromberg [C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> 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.com> wrote in message
>> news:(E-Mail Removed)...
>> > "Lloyd Sheen" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> 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

 
Reply With Quote
 
=?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
Guest
Posts: n/a
 
      07-04-2007
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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does timer in Web Service Global.asax block my Web Service from processing web-site requests? Leo Violette ASP .Net Web Services 0 04-17-2009 12:39 AM
dynamically generating html vs using html scaffolding? Faisal Vali Javascript 10 06-21-2008 04:31 PM
InvocationTargetException when calling "new Service()" in Axis web service to call another web service Michael Averstegge Java 0 01-10-2006 11:05 PM
Generating a WSDL from a document-oriented Web Service? mygoogleac Java 0 10-12-2004 01:30 PM
Generating a WSDL from document-oriented Web Service mygoogleac Java 0 09-30-2004 12:38 AM



Advertisments