Web.config中的HTML字符串 [英] HTML string in Web.config
问题描述
您好我想在应用设置中添加html代码,如下所示
感谢您购买,您可以添加新的< a href ='NewItem.aspx'>获取新商品< / a>
i在web.config中添加如下所示
< appSettings>
< key = 成功 value = 感谢您的购买,您可以添加新的& lt; a href ='NewItem.aspx '& gt;获取新商品& lt; / a& gt; >
< / appSettings >
并在页面加载中调用
lblSuccess.Text = Server.HtmlEncode(ConfigurationManager.AppSettings [ 成功]。ToString())。ToString()
我的aspx如下所示
< div>
< asp:Label Id = lblSuccess runat = 服务器 />
< / div >
我希望文本是html格式,而不是文本格式,它使用HtmlEncode或HtmlDecode作为文本。
而不是标签使用 LiteralControl
它可能有所帮助(不确定)
顺便问一下,为什么要从web.cofig中选择一条消息?为什么不为这些任务管理.cs类?
我建议使用名为 CommonMethods 的[静态]类,其方法名为 GetGreetingsMessage()。
你可以通过
CommonMethods.GetGreetingsMessage ()
而不是在标签中显示结果显示在TextBox如
< div < span class =code-keyword>>
< asp:textbox id = txtSuccess runat = 服务器 style = border:none; readonly = true xmlns:asp = #unknown / >
< / div >
txtSuccess.Text = Server.HtmlEncode(ConfigurationManager.AppSettings [ 成功]。ToString())。ToString()
你可以添加一些CSS在这种情况下,文本框看起来像一个标签;
祝您好运!
进行以下更改
--- ------------------------
< appsettings >
< key value = 感谢您的购买,您可以添加新的< a href ='NewItem.aspx'> New Item< / a> >
< / key > < / appsettings >
创建一个DIV来显示消息。
< div runat = server id = divSuccess >
< span class =code-keyword>< / div >
将应用程序设置中的数据绑定到创建的Div。
divSuccess.InnerHTML = ConfigurationManager.AppSettings [ 成功]。ToString();
Hi i wanted to add html code in app settings which is like below
Thank you for purchasing you can add new one <a href='NewItem.aspx'>Get new Item</a>
i added this one as below in web.config
<appSettings>
<key="Success" value="Thank you for purchasing you can add new one <a href='NewItem.aspx'>Get new Item </a>">
</appSettings>
and called in page load as
lblSuccess.Text=Server.HtmlEncode(ConfigurationManager.AppSettings["Success"].ToString()).ToString()
My aspx look like below
<div>
<asp:Label Id="lblSuccess" runat="Server" />
</div>
I want the text to be in html format not in text format it is comming as text either i used HtmlEncode or HtmlDecode.
Instead of Label Use LiteralControl
it might help (not sure)
By the way, why to pick a message from web.cofig? Why not you manage a .cs class for such tasks ?
I will recommend to have a [Static] class named CommonMethods with Method named GetGreetingsMessage().
and you may pick it up via
CommonMethods.GetGreetingsMessage()
Hi,
Instead of shoowing the result in a Label show it in a TextBox like
<div> <asp:textbox id="txtSuccess" runat="Server" style="border:none;" readonly="true" xmlns:asp="#unknown" /> </div>txtSuccess.Text=Server.HtmlEncode(ConfigurationManager.AppSettings["Success"].ToString()).ToString()
you may add some css for the textbox to look like a label in this case;
Best of luck!
Do the Following Changes
---------------------------
<appsettings> <key value="Thank you for purchasing you can add new one <a href='NewItem.aspx'>New Item</a>"> </key></appsettings>
Create a DIV to show the Message.
<div runat="server" id="divSuccess"> </div>
Bind the Data From the Application Setting to Div Created.
divSuccess.InnerHTML=ConfigurationManager.AppSettings["Success"].ToString();
这篇关于Web.config中的HTML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!