There's a moment in my page where I connect to a database and retrieve some data. One field in special is html code. I want to display it in my page as html inside some control that understands it.
What are my options?
Use a literal.
.aspx:
<asp:Literal runat="server" ID="myLiteral" />
codebehind:
myLiteral.Text = "<h2> this is a h2 html tag</h2>";
this will print out
This is a h2 html tag
Related
I have the following ASP.NET Literal Control displayed on my page
<div class="col-md-8 text-justify">
<p>
<asp:Literal ID="Literal1"
Mode="PassThrough"
Text= "<%#:Item.Description %>"
runat="server">
</asp:Literal>
</p>
</div>
This control is bound to a field in my SQL Server Table and a column called Description in the table contains the text with HTML tags like <p> <ul> <br> etc.
However when the text is displayed in the Literal control, it is displayed as-is i.e the HTML does not get rendered.
If the Literal control does not support rendering, what other options do I have?
Your problem isn't with the Literal control. It's the way you embedded the HTML. Try this:
<asp:Literal ID="Literal1"
Mode="PassThrough"
Text= "<%# Item.Description %>"
runat="server">
</asp:Literal>
Notice I left out the colon? That colon is there to prevent injection attacks, where the contents of the value being embedded might come from a user. But if you trust the HTML content, then removing the colon will embed the HTML and allow it to render properly instead of escaping it.
I have an asp:TextBox that I need to convert to a FreeTextBox. The following is my asp:TextBox aspx code:
<%# Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>
<asp:TextBox ID="tbxRiskDesc" runat="server" Width="90%" TextMode="MultiLine" Rows="6" onblur="Resize(this);" onkeypress="Resize(this);" ></asp:TextBox>
<rad:RadSpell ID="spellRiskDesc" runat="server" Width="5px" ControlToCheck="tbxRiskDesc" WordIgnoreOptions="UPPERCASE" FragmentIgnoreOptions="EmailAddresses,Urls" DictionaryLanguage="en-AU" SupportedLanguages="en-AU,English" AllowAddCustom="true" DictionaryPath="~/RadControls/Spell/TDF/" SpellCheckProvider="EditDistanceProvider" EditDistance="2" ButtonType="ImageButton" />
The following code is in the aspx.cs code:
Page_Load:
tbxRiskDesc.Attributes.Add("onchange", "setDirty();");
Reset_Data:
SetTextCurrentValue(tbxRiskDesc, dtEditTable, "RiskDesc");
Clear_Data:
SetTextValue(tbxRiskDesc, "RISK TITLE & DESC.:");
When I replace the "asp:TextBox" code in the aspx file with the following, the code behind has errors and i dont know how to change the code for the FreeTextBox for the Page_Load, Reset_Data & Clear_Data sections.
<FTB:FreeTextBox ID="tbxRiskDesc" runat="server"></FTB:FreeTextBox>
The reason for the change over is because we need to allow the users to put bullet points and hyperlinks into the text boxes.
All help is appreciated.
You have two options:
recommended: replace the textbox with RadEditor which has built-in integration with RadSpell
use the RadSpell API to spellcheck the FreeTextBox control: You have to get a reference to the body element of the iframe content area of FreeTextBox. After that you can implement a custom text source similarly as it is done for RadEditor in the following forum thread: Problem with spellcheck.
Using the RadEditor's get_contentAreaElement() method you can get a reference to RadEditor's iframe content area element and after that to get a reference to the body tag of the iframe:
var editorSource = $find('RadEditor1').get_contentAreaElement().contentWindow.document.body;
You should see in the FreeTextBox documentation or forums how to get a reference to the body element and update the above line in the provided in the forum article custom text source code.
WIth aspx, there are UI part(.aspx) and code behind(.aspx.vb).
In Markup, there is some html element, like Table with ID='Tab1'
How to got the html element Table in code behind to change its attributes?
Make the table accessible in code behind by assigning it id and making it runat="server"
<table id="tbl" runat="server" >....
Hello I found next strange as for me behavior of Literal in Asp MVC out put and I don't know how to fix it.
I have next part of html code on aspx page
...
<p class="description">
<asp:Literal ID="lblDescription" runat="server" EnableViewState="false"></asp:Literal>
</p>
...
On page load event I try to show user text:
lblDescription.Text = stringVar;
string var can contain other html tag like p, div, etc
But when my page loaded I see all html that should be inside was created under this element.
some text
Does any one know why ?
thanks
Try this:
<asp:Literal ID="lblDescription" Mode="PassThrough" runat="server" EnableViewState="false"></asp:Literal>
MSDN: Mode Property
I've got the ImageButton wrapped inside a form tag with runat="server" but STILL getting this error at runtime. The form tag is at the very beginning (before my table) and end tag is at the end (after the table).
<td>
<div>
<div id="pay-Button"><asp:ImageButton ID="PayButton" ImageUrl="<%=PayButtonImageUrl %>" OnClick="RedirectTest" runat="server" /></div>
</div>
</td>
You can't have managed controls within a <form> tag without the runat='server'. ASP.Net supports multiple form tags, but with only one of them having a server-side designation. Also, I don't believe that HTML supports nested forms. You'll either want to have it be a non-managed control in a separate form or remove the nested <form> tag from the server-side form.
Look here for further explanation.
remove the ImageUrl="<%=PayButtonImageUrl %>" part, I don't believe you can use those inline snippits for server control properties (unless you're databinding)
Does your tag also have
runat="server"
as an attribute?
It would be helpful if you showed more of your code so we can help.