Display of html contents in C# - c#

I want to display PDF to HTML contents parallel. For the conversion I used iTextSharp from PDF to HTML. The HTML contents are in a format like:
<span style="background: cyan">NLJJCN+BellMT</span>
<span style="background: cyan">11.353696472168pt</span>
so I tried with div to display the contents it was overlapping .. then label same problem as div. At last I tried HTMLeditor
<asp:TextBox ID="txtb_output" runat="server" TextMode="MultiLine" width=" 493px" height=" 485px" ></asp:TextBox>
<asp:HtmlEditorExtender ID="HtmlEditorExtender2" runat="server" TargetControlID="txtb_output"></asp:HtmlEditorExtender>
but in this it was not taking style .. normally text was displayed. Can anyone please help me how can I display the HTMLcontents in the browser. I am working on web application.
Thank you in advance

If I did not misunderstand, you have some html and you just want to show it on the browser from code-behind? If it is so, you can place a Literal control with Mode="PassThrough" and assign its Text property from code-behind. e.g.
aspx markup:
<asp:Literal ID="lt" Mode="PassThrough" runat="server" />
code-behind:
//...
lt.Text = "<span style='background-color:red'>It works!</span>";

Related

Tag a link attribute data-image can't display value c#

I want using gallery thumbnail css and js from bootstrap snippet Easy image gallery in modal. When I'm using control from c# it's cannot display.
<asp:HyperLink runat="server" class="thumbnail" href="#" data-image-id="" data-toogle="modal" data-image='<%# Eval("Image") %>' data-target="#image-gallery">
<dx:ASPxBinaryImage runat="server" class="img-responsive" ID="img" Eval='<%# Eval("Image")%>' Height="150px" Width="150px"></dx:ASPxBinaryImage>
</asp:HyperLink>
My data-image tag a link don't same show like src from tag img. A data-image value System.Byte[]
This make my modal show picture cannot display

add hyperlink to customized username area in aspx webpage

In my aspx web page there is one area to display username like Hi, Sruthy. It is customized to each user. So now I want to add hyperlink to this area how can I do it?
So my code is:
<div id="Displayname" class="displayName" runat="server">
<a href="Personalinfo.aspx" target=_blank></a>
</div>
you can use <asp:Hyperlink>
HTML
<asp:HyperLink id="hl1"
NavigateUrl="#"
Text=""
runat="server"/>
C#
you can alter the href or Text in C# using
hl1.NavigateUrl = "#";
hl1.Text = "Hi,Sruthy";

How to take a Sql column value and translate the html into a asp label

Sql column value (generated from a InfoPath RTF control):
<strong xmlns="http://www.w3.org/1999/xhtml"><font color="#7030a0">This</font></strong> is a <font xmlns="http://www.w3.org/1999/xhtml" color="#ff0000"><strong>richtextfield</strong></font>
I have a label in asp.net:
<asp:Label ID="lblOne" runat="server" Text=""></asp:Label>
How can I translate the column value to display the output in the asp label.
Example:
The asp label above would display: `this (in bold and in color) is a richtextfield(in bold and in color)`
You'd probably be better served with a Literal value since you're using raw HTML.
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.literal.mode(v=vs.110).aspx
<asp:Literal ID="Literal1" runat="server" Mode="PassThrough"></asp:Literal>
In the code-behind
Literal1.Text = yourSQLValue;
You should consider not placing HTML directly into your page however.

Is there any alternative for <br /> in asp.net?

I was trying to display lblName1 and lblName2 only if they have text. Even when i dont have any value for lblName2, the break still has an impact. Can someone please advice me if there is any other way to display or conditionally display
<asp:Label ID="lblName1" runat="server" Visible= "false" ></asp:Label> <br />
<asp:Label ID="lblName2" runat="server" Visible= "false"> </asp:Label>
Thanks in advance..
Give the label a CSS class name and set the margin for that class:
<asp:Label ID="lblName1" CssClass="Testing123" runat="server" Visible= "false" ></asp:Label> <br />
.Testing123{ margin-bottom: 20px; }
If the Label is not rendered then no gap will be created.
You might consider adding a litteral to handle the br and this way play with its visibilty :
<asp:Literal runat=server Id=C_lit_Br><br /></asp:Literal>
with in your codebehind :
if (!lblName2.Visible)
C_lit_Br.Visible=false;
It is a quick patch, but it should work.
It is better to use literal in that case:
In literal text you also write html in it
wrap the labels in p tags:
<p><label1></p>
<p><label2></p>
Going with what you have and ignoring using any code behind changes, you can use some css to provide a break without using a <br /> tag.
By this, I mean if you were to give your <label> controls a css class, class="labelStyle
.labelStyle{
float: left;
clear: left;
}
Your html produced would look like
<span class="labelStyle">Some Text</span><span class="labelStyle">More Text</span>
If there is no value in the Labels, then your html would contain two empty span tags.
This will move the 2nd label onto the next line. However this may not fit in with the rest of your html, and because you are floating elements, then your overall layout might break.
An example is here http://jsfiddle.net/2v93f/

data binding to html tag in asp.net

I was just wondering if it is possible to bind data using DataBinder.Eval on a html tag with runat=server attribute. For example i want to do something like:
<a href=<%#DataBinder.Eval(Container.DataItem, "file_name") %> runat="server" />
but it doesn't work. does this mean i have to use the asp.net hyperlink control?
Cheers,
Stephen
try this instead:
<a href='<%#Eval("file_name") %>' >Link text goes here...</a>
It works if the element is inside a bindable control, like a DataList or a GridView, and you don't need server control:
<a href='<%# Eval("file_name") %>' />

Categories

Resources