将html字符串转换为对象 [英] Converting html string to object

查看:274
本文介绍了将html字符串转换为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我需要找到一种从数据库中读取html类型字符串并将其添加到页面上的占位符控件的方法

然后我需要能够在运行时填充那个html字符串中的字段。


html字符串可能看起来像这样 < table>< tr>< td>名字< / td>< td><输入

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


有没有办法将此字符串转换为您可以访问的对象

比如_firstname.text或_firstname.innerhtml,任何可以设置

值的东西都会很棒。


有谁知道一篇文章或者有一个想法怎么去

这样做?


谢谢,


Wouter

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

推荐答案



" Wouter vanEck" < WO *********** @ smart-quotes.com>在消息中写道

news:uP ************** @ TK2MSFTNGP11.phx.gbl ...

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

我需要找到一种从数据库中读取html类型字符串并将其添加到页面上的占位符控件的方法然后我需要能够
填充字段在运行时处于该html字符串中。

html字符串可能如下所示"< table>< tr>< td> First
Name< / td>< td>< input name = _firstname runat = server id = _firstname ....>< / td>< / tr>< / table>"

有没有办法将此字符串转换为一个对象,您可以像_firstname.text或_firstname.innerhtml那样
访问,任何可以
设置值的东西都会很棒。

有没有谁知道一篇文章或者知道如何去做呢?

谢谢,

Wouter
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



您可以在页面上放置一个占位符(比如说它叫做plc1) n代码

执行以下操作

plc1.controls.add(新文字控件(yourhtmltext))


然后回发获取request.form(" _firstname")。从hmtltext中取出噱头



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





感谢您的快速回复,我实际上是想把一个值推到场上。
。阅读部分很简单,就像你说的那样,但我需要在回发后才能填充这个字段。


Wouter


" vMike" <弥**************** @ noZorY.geZwaYrrenY.com>在消息中写道

news:cr ********** @ ngspool-d02.news.aol.com ...
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>在消息中写道
新闻:uP ************** @ TK2MSFTNGP11.phx.gbl ...

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

我需要找到一种从数据库中读取html类型字符串的方法,并将
添加到页面上的占位符控件,然后我需要能够填充
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
字段在运行时处于该html字符串中。

html字符串可能如下所示"< table>< tr>< td> First
the fields that were in that html string at run time.

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


名称< / td>< td>< input


Name</td><td><input

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

有没有办法将这个字符串转换成一个对象,你可以
name=_firstname runat=server id=_firstname ....></td></tr></table>"

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


访问

如_firstname.text或_firstname.innerhtml,任何事情都可以能够
like _firstname.text or _firstname.innerhtml, any thing to being able to


设置

价值会很棒。

是否有人知道某篇文章或有想法如何关于这样做你需要花钱吗?

谢谢,

Wouter
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


你可以把一个占位符(比如叫做plc1)放在上面一个页面然后在


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



代码执行以下操作
plc1.controls.add(New literalcontrol(yourhtmltext))

然后在回发上获取request.form(" _firstname")。拿出hmtltext的


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



" Wouter vanEck" < WO *********** @ smart-quotes.com>在消息中写道

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

我需要找到一种从数据库中读取html类型字符串并将其添加到页面上的占位符控件的方法,然后我需要能够填充运行时在该html字符串中的字段。

html字符串可能如下所示"< table>< tr>< td> First
Name< / td>< td>< input
name = _firstname runat = server id = _firstname ....>< / td>< / tr>< / table>"

有没有办法将这个字符串转换成一个你可以访问的对象,如_firstname.text或_firstname.innerhtml,任何能够设置的东西
价值会很棒。

有没有人知道一篇文章或有想法如何去做这个?
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??




你不能直接这样做。如果您可以将数据库内容转换为磁盘上的

用户控件(.ascx文件),则可以使用LoadControl加载它。


除此之外,你必须自己解析HTML字符串,使用

正则表达式或其他东西。


这似乎是基于以下假设设计的你可以将一个

字符串变成一组服务器端控件。如果事实证明这不是

的情况,如果你不能做用户控制技巧,那么也许你可以稍微改变设计。如果数据库中的字符串更容易解析字段,那么你会有更好的运气。例如,它可以

包含像%fieldName%这样的字符串。这很容易解析。解析比runat =" server"更容易解析
id =" _firstname"。

John Saunders



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


这篇关于将html字符串转换为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆