如何从SQL数据库写入ASP标记 [英] How to write asp tags from sql database

查看:88
本文介绍了如何从SQL数据库写入ASP标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我将包含多个asp标记的String存储到数据库中. 这是我存储的内容.

So, I have store to a database a String that include several asp tags..
Here is what I have stored..

<asp:HyperLink ID="hmembername" runat="server" NavigateUrl=''<%# "friendprofile.aspx?friendid="2 %>''>John</asp:HyperLink> &#0187; <asp:HyperLink ID="hmembername" runat="server" NavigateUrl=''<%# "friendprofile.aspx?friendid="1 %>''>William</asp:HyperLink><p style="padding-left: 10px;"><em> Hello......</em></p>


我通过使用listview来称呼它.


and I call it by using listview.

<%# Eval("post") %>



但是当它触发时,它只读取<em><p>的html标签.
但是它不会解析/写入<asp:HyperLink>的asp标记.
因此,asp标记对输出无效,而html标记仍对输出有效.
有人可以告诉我如何解析asp标签吗?
我对这些ASP.Net还是陌生的.所以,请.



But when it triggers,it only read the html tags which is <em> or <p>.
But it doesnot parse/write the asp tags which is <asp:HyperLink>.
So, the asp tags have no effect to the output, meanwhile the html tags still have it effect to the output.
Can someone please tell me how to do parse the asp tags?
I am still new in these ASP.Net things... So, please.

推荐答案

您可以在代码后面执行此表单,但不能执行此操作因为我们的事件顺序将不正确,并且服务器端控件将无法呈现.

您可能要做的是在需要插入标记的位置添加一个PlaceHolder控件,然后在pageload事件(包装在!IsPostBack中)的后面填充标记表单代码,如下所示:

假设sql调用返回了一些字符串变量以及填充新控件所需的数据:

You can do this form code-behind but not the way you are doing it since our sequence of events will be incorrect and the server side controls will not get rendered.

What you might do is to add a PlaceHolder control where you need to insert markup and then populate the markup form code behind in the pageload event (wrapped in a !IsPostBack) as:

Assume that the sql call returns a few string variables with the data required to fill the new control:

HyperLink hl = new HyperLink();
hl.NavigateUrl = variable_that_contains_url;
hl.Text = variable_that_contans_text_to_display;
// and so on....

PlaceHolder1.Controls.Add(hl);



您需要弄清楚确切的代码,但这应该可以帮助您入门.



You''ll need to figure the exact code but that should get you started.


您可以将对象存储在sql列中,但是我认为您需要将该列设置为BLOB或XML. em保存而不是保存的原因是因为其他标签中的属性.最后一个双引号被选择为字符串的开始,而最后一个"是结束.这样就保存了em和p.

所以您需要使用一个参数来存储字符数组
You can store the objects in a sql column, but I think you need to set the column to BLOB or XML. The reason why the em saves, and not the others, is because of the attributes in the other tags. the last double quote " was picked up as the start of the string, and the last " was the end. Thus em and p was saved.

So you need to use a parameter to store the character array
Update table set html=@html
eg parameter 
Dim paramHTML As SqlParameter
paramHTML = New SqlParameter("@html", SqlDbType.blob)
paramHTML.Value = sHTML
myCommand.Parameters.Add(paramHTML)


但不利的是,您可以提取它们,但我看不到如何将它们重新构造为网页上的html对象.

服务器需要读取对象,因此可以将它们转换为html,然后发送回浏览器进行解码.

您可能需要考虑在数据库中存储纯HTML.
[edit]
您可能需要考虑在保存之前对字符串进行html编码,并在提取过程中进行解码.

总的来说,将html存储在数据库中是一个坏主意.我试过一次,最后处理和"是麻烦,然后才值得.所以我选择了一个大参数数组,并进行了拆分以将它们分离出来


But on the downside, you can extract them, but I don''t see how you can reconstitute them back into html objects on your web page.

The objects need to be read by the server, so they can be converted into html, and sent back to the browser for decoding.

You may want to consider storing plain html in the database instead.
[edit]
You may want to consider html encoding the string before saving, and decoding during extraction.

Overall in the end, storing html in the database is a bad idea. I tried it once, and dealing with the " and slashes in the end, was more trouble then it was worth. So I went with a large parameter array, and just did a split to separate them back out

1498kbs|640x480|22000hz


这篇关于如何从SQL数据库写入ASP标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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