468,134 Members | 1,214 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,134 developers. It's quick & easy.

Converting html string to object

Hi,

I need to find a way to read a html type string from a database and add it
to a placeholder control on the page and then I need to be able to populate
the fields that were in that html string at run time.

The html string may look like this "<table><tr><td>First Name</td><td><input
name=_firstname runat=server id=_firstname ....></td></tr></table>"

Is there a way to convert this string into an object which you could access
like _firstname.text or _firstname.innerhtml, any thing to being able to set
the value would be great.

Is there anyone who knows about an article or has an idea how to go about
doing this??

Thanks,

Wouter
Nov 19 '05 #1
10 3060

"Wouter vanEck" <wo***********@smart-quotes.com> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
Hi,

I need to find a way to read a html type string from a database and add it
to a placeholder control on the page and then I need to be able to populate the fields that were in that html string at run time.

The html string may look like this "<table><tr><td>First Name</td><td><input name=_firstname runat=server id=_firstname ....></td></tr></table>"

Is there a way to convert this string into an object which you could access like _firstname.text or _firstname.innerhtml, any thing to being able to set the value would be great.

Is there anyone who knows about an article or has an idea how to go about
doing this??

Thanks,

Wouter

You can put a placeholder (say it is called plc1) on a page and then in code
do the following
plc1.controls.add(New literalcontrol(yourhtmltext))

Then on postback get the request.form("_firstname") . Take the runat out of
the hmtltext
Nov 19 '05 #2
Hi,

Thanks for your quick response but I was actually trying to push a value to
the field. The reading part is easy, just like you said, but I need to be
able to populate the field after a postback.

Wouter

"vMike" <Mi****************@noZorY.geZwaYrrenY.com> wrote in message
news:cr**********@ngspool-d02.news.aol.com...

"Wouter vanEck" <wo***********@smart-quotes.com> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
Hi,

I need to find a way to read a html type string from a database and add it to a placeholder control on the page and then I need to be able to populate
the fields that were in that html string at run time.

The html string may look like this "<table><tr><td>First

Name</td><td><input
name=_firstname runat=server id=_firstname ....></td></tr></table>"

Is there a way to convert this string into an object which you could

access
like _firstname.text or _firstname.innerhtml, any thing to being able to

set
the value would be great.

Is there anyone who knows about an article or has an idea how to go about doing this??

Thanks,

Wouter

You can put a placeholder (say it is called plc1) on a page and then in

code do the following
plc1.controls.add(New literalcontrol(yourhtmltext))

Then on postback get the request.form("_firstname") . Take the runat out of the hmtltext

Nov 19 '05 #3
"Wouter vanEck" <wo***********@smart-quotes.com> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
Hi,

I need to find a way to read a html type string from a database and add it
to a placeholder control on the page and then I need to be able to
populate
the fields that were in that html string at run time.

The html string may look like this "<table><tr><td>First
Name</td><td><input
name=_firstname runat=server id=_firstname ....></td></tr></table>"

Is there a way to convert this string into an object which you could
access
like _firstname.text or _firstname.innerhtml, any thing to being able to
set
the value would be great.

Is there anyone who knows about an article or has an idea how to go about
doing this??


You can't do this directly. If you can turn the database contents into a
user control (.ascx file) on disk, then you can load it with LoadControl.

Other than that, you'll have to parse the HTML string by yourself, using
regular expressions or something.

This appears to have been designed on the assumption that you can turn a
string into a set of server-side controls. If this turns out not to be the
case, and if you can't do the user control trick, then perhaps you could
change design a bit. If the string in the database were a bit easier to
parse for "fields", you'd have better luck with it. For instance, it could
contain strings like %fieldName%. That's pretty easy to parse for. It's a
lot easier to parse for than runat="server" id="_firstname".

John Saunders
Nov 19 '05 #4
Hi John,

It is not the answer I was hoping for, I am currently trying to work with
rendering the string to the page.. same result unless I am doing it wrong.

Wouter

"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:Ot**************@TK2MSFTNGP09.phx.gbl...
"Wouter vanEck" <wo***********@smart-quotes.com> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
Hi,

I need to find a way to read a html type string from a database and add it to a placeholder control on the page and then I need to be able to
populate
the fields that were in that html string at run time.

The html string may look like this "<table><tr><td>First
Name</td><td><input
name=_firstname runat=server id=_firstname ....></td></tr></table>"

Is there a way to convert this string into an object which you could
access
like _firstname.text or _firstname.innerhtml, any thing to being able to
set
the value would be great.

Is there anyone who knows about an article or has an idea how to go about doing this??


You can't do this directly. If you can turn the database contents into a
user control (.ascx file) on disk, then you can load it with LoadControl.

Other than that, you'll have to parse the HTML string by yourself, using
regular expressions or something.

This appears to have been designed on the assumption that you can turn a
string into a set of server-side controls. If this turns out not to be the
case, and if you can't do the user control trick, then perhaps you could
change design a bit. If the string in the database were a bit easier to
parse for "fields", you'd have better luck with it. For instance, it could
contain strings like %fieldName%. That's pretty easy to parse for. It's a
lot easier to parse for than runat="server" id="_firstname".

John Saunders

Nov 19 '05 #5

"Wouter vanEck" <wo***********@smart-quotes.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

Thanks for your quick response but I was actually trying to push a value to the field. The reading part is easy, just like you said, but I need to be
able to populate the field after a postback.

If that is you only option then you could probably override the render of
the placeholder and do a some kind of string replace before output, but you
might want to consider some other approach.
Nov 19 '05 #6
"Wouter vanEck" <wo***********@smart-quotes.com> wrote in message
news:uf**************@TK2MSFTNGP15.phx.gbl...
Hi John,

It is not the answer I was hoping for, I am currently trying to work with
rendering the string to the page.. same result unless I am doing it wrong.


Are you aware that the runat="server" in these controls is meaningless?

John Saunders
Nov 19 '05 #7
:-)

Now I do...

"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:OK**************@TK2MSFTNGP14.phx.gbl...
"Wouter vanEck" <wo***********@smart-quotes.com> wrote in message
news:uf**************@TK2MSFTNGP15.phx.gbl...
Hi John,

It is not the answer I was hoping for, I am currently trying to work with rendering the string to the page.. same result unless I am doing it
wrong.
Are you aware that the runat="server" in these controls is meaningless?

John Saunders

Nov 19 '05 #8

"Wouter vanEck" <wo***********@smart-quotes.com> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
Hi,

I need to find a way to read a html type string from a database and add it
to a placeholder control on the page and then I need to be able to populate the fields that were in that html string at run time.

The html string may look like this "<table><tr><td>First Name</td><td><input name=_firstname runat=server id=_firstname ....></td></tr></table>"

Is there a way to convert this string into an object which you could access like _firstname.text or _firstname.innerhtml, any thing to being able to set the value would be great.

Is there anyone who knows about an article or has an idea how to go about
doing this??

Thanks,

Actual something like this might work for you. plc1 is a placeholder
control.
dim strtext as string = "<table><tr><td>First Name</td><td><input
runat='server' id='_firstname'></td></tr></table>"
dim ctrl as control = parsecontrol(strtext)
ctrl.id = "ctrl1"
dim ctrl2 as htmlinputcontrol = ctype(ctrl.controls(1),htmlcontrol)
ctrl2.value = "yourvaluefor input box"
plc1.controls.add(ctrl)
Nov 19 '05 #9
On Fri, 7 Jan 2005 11:18:14 -0700 in
microsoft.public.dotnet.framework.aspnet, "Wouter vanEck"
<wo***********@smart-quotes.com> wrote:
Hi,

I need to find a way to read a html type string from a database and add it
to a placeholder control on the page and then I need to be able to populate
the fields that were in that html string at run time.

The html string may look like this "<table><tr><td>First Name</td><td><input
name=_firstname runat=server id=_firstname ....></td></tr></table>"

Is there a way to convert this string into an object which you could access
like _firstname.text or _firstname.innerhtml, any thing to being able to set
the value would be great.

Is there anyone who knows about an article or has an idea how to go about
doing this??

Thanks,

Wouter


Hi Wouter,

Not sure off hand how to convert your string into an object, but you
can easily convert your string into a control like so:

string sSomeHtmlString = get string from database();
Control ctrl = Page.ParseControl(sSomeHtmlString); // Create control
Form1.Controls.Add(ctrl); // Add control to the Form

During postbacks, using FindControl("_firstname") to get at individual
values. Likewise you could also set each value as needed.

Hopefully this is what you're looking for.
Roger

Nov 19 '05 #10
Hi Roger,

Excellent!!! Works like a charm.

Wouter

"Roger Helliwell" <rh********@telus.net> wrote in message
news:tt********************************@4ax.com...
On Fri, 7 Jan 2005 11:18:14 -0700 in
microsoft.public.dotnet.framework.aspnet, "Wouter vanEck"
<wo***********@smart-quotes.com> wrote:
Hi,

I need to find a way to read a html type string from a database and add itto a placeholder control on the page and then I need to be able to populatethe fields that were in that html string at run time.

The html string may look like this "<table><tr><td>First Name</td><td><inputname=_firstname runat=server id=_firstname ....></td></tr></table>"

Is there a way to convert this string into an object which you could accesslike _firstname.text or _firstname.innerhtml, any thing to being able to setthe value would be great.

Is there anyone who knows about an article or has an idea how to go about
doing this??

Thanks,

Wouter


Hi Wouter,

Not sure off hand how to convert your string into an object, but you
can easily convert your string into a control like so:

string sSomeHtmlString = get string from database();
Control ctrl = Page.ParseControl(sSomeHtmlString); // Create control
Form1.Controls.Add(ctrl); // Add control to the Form

During postbacks, using FindControl("_firstname") to get at individual
values. Likewise you could also set each value as needed.

Hopefully this is what you're looking for.
Roger

Nov 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by D Elkins | last post: by
2 posts views Thread by Asbjørn Ulsberg | last post: by
3 posts views Thread by Wallace | last post: by
4 posts views Thread by gg9h0st | last post: by
5 posts views Thread by k.vanderstarren | last post: by
1 post views Thread by Michelle Sollicito eBarster | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.