literal control text rendering is not properly set in asp.net? - c#

In my asp.net web application, i have used liter control for displaying HTML data.Whenever user clicks the button, i will have a set of html data and needs to display it in the literal control.
Suppose if i have HTML table data or any other text with some formatting tags then it also displayed in literal control perfectly...
But i have a problem with displaying this HTML TABLE data(particularly this). for example, i have this HTML TABLE data in string.In debugging mode i just copied the string value and stored it as .html file.So, If i open the file in browser it shows the full table data(Way 1).But in my project, i just assigned the string value to literal control text.
literal1.text=htmlString;
But i when looked at the browser, my literal control shows only from part of the html table data.particularly,the first column is fully not shown and also part of the second row is not shown(Way 2).
I little bit doubt about whether it is a alignment problem.I can't able to set the alignment of literal control anyway...
Please guide me to get out of this issue...
I have attached print screen of the both original table data displayed in browser(Image 1) and also literal control table data(Image 2)...
* Image 1 for Way 1*
* Image 2 for Way 2 *

The first thing I'd recommend is to compare the resulting html markup and affecting CSS using Firebug or another web developer tool. That should tell you where the differences are.
Based on your screenshots it looks as though the difference comes down to styling so either your HTML differs from one version to another and/or the CSS.
Can you post some code to go with your question?

Related

Hide part of text temporarily, show after user clicks certain element

I'm making a detail page about certain items.
This detail page can contain large blocks of text, and the customer would like to only show the first 100 letters and then put a " ... more " at the end.
When the user clicks this " ... more " the rest of the text can be shown.
Biggest problem: the text is currently is a CMS and has large varieties. Some is pure text, some have html elements in them ...
I tried to cut off the text and put them in spans. Then i could show/hide these spans as i please. The issue here is that there can be a starting element of a certain tag in the first span and the closing element can be in the second span. This causes the DOM hierarchyto be faulty and the result is never pretty.
Does anyone know a ( other ) way to achieve this or a library i can use ?
To be able to extract "readable" characters you need to get the content into a plain text format (get rid of the mark-up).
Since the content is stored in a cms it is likely that the content is structured to be well formed - thus xhtml.
If that is the case you can treat the content as XML. Get the root node and get the innertext property there-of. Then you will have plain text - no tags - and can easily cut it after the first 100 characters or whatever the requirement is.
Hopefully the content doesn't contain js/css!
Edit:
It seems that the markup must be retained.
Try the following xsl to transform and truncate the content:
https://gist.github.com/allen/65817

Retrieve text from database and format it on the front end of the website

I have some text currently stored in my database table as nvarchar.
I am currently retrieving the text using a stored procedure and binding it to a literal within a gridview on the front end.
What I would like to do is to retrieve the text and then format it , like inserting line spaces and making
certain area bold. Is it possible to do so ? Can anyone give me an idea of how it can be done ?
One idea thats striking me is to use XML while storing the text . But even if I do that how would I make a certain part of the text bold and include line spaces.
So currently, my text is stored in the database table column nvarchar(max) as:
This is the heading this is the content
What I would like to do is to display the above within a gridview like:
**This is a Heading** (heading in bold)
This is the content
The simplest method (one I have used several times) is to store the html in the table like this:
<h1>This is the heading</h1>This is the content
You will have to add special handling for working with html, but it works just fine.
You can also store the header string in one field, and body in another.
Short of that, you would have to have some indicator telling the front which part of the string should be bolded, etc. and that can get very complex
Short answer is that this is possible but takes some work.
You first need to decide in what format are you going to store the data and how can you specify format on the client side, before text is entered into database.
If you have WYSIWYG editor for text – html conversion you can try storing the HTML. This will be the easiest way in terms of storage.
If you decide to use this method note that you’ll need to do a lot of validation on the server to avoid cross site scripting attacks. Shortly put – make sure the HTML you get on the server doesn’t contain any javascript or any tags apart from those you want to support.
Its better to use Editor of AJAX Toolkit, doesnt required any other thing, its a complete editor, you can even color your font as u wanted.

C# simple html editor - how to search and replace content

Today i'm working on simple html editor in visual c#.
My goal is to open pure html file from local drive (Opendialog load into string or load into webbrowser completed) and allow to edit key fragments.
application should find specific divs and return the full content of that div to textbox or better to combobox (compare to combobox item and show it).
if i change the textbox (or pick up another item from combobox) application should present changes on webbrowser control.
Then i need to print this html as is seen on webbrowser control.
Last thing is to save modified hmtl overwrting original and adding comment with changes at bottom of the html file.
I want to know how to perform search&replace in this project? How to "adress" content of a div?
Better is string searching, indexof, string.replace etc. Or drown into DOM-thing (i don't know both at the moment).
How to present changes on html preview on webcontrol component? And finally overwrite a file?
Code's examples appreciated :)
Thanks in advance
You should use HtmlAgilityPack for that, it makes working with DOM a lot more easier, than parsing it yourself.
http://htmlagilitypack.codeplex.com/
For example, here is how to get all divs
var elements = hdoc.DocumentNode.Descendants("div") /.Where(.your conditions..))/;

Format RTF text into multiple textboxes

I have a richtextbox on my wpf form that the user types into, with no restrictions on length. However, on my active reports output, I have pages with fixed-space textboxes on each page. Is there any way to figure out how much of the rich text will fit into a textbox, write it out, and then continue writing the rest on the next page until i run out of text to write?
You can measure the length of plain text on an ActiveReports Page using the Page object's MeasureText method. See the following documentation: http://www.datadynamics.com/help/activereports6/ActiveReports.Document~DataDynamics.ActiveReports.Document.Page~MeasureText.html
If you have RTF output (I'm not sure if you do or not based on the information provided) it is probably not feasible to manually measure the text and break it up simply because RTF text is complex and breaking into parts is more difficult. However, the RichEdit/RTF control in ActiveReports should be able to paginate/page break it fine if you can let that control grow.

How to create aspx page on runtime and place literal control?

I have an requirement where i have to display some content on iframe dynamically. Let me explain my scenario. I have a form where i have to display some html text. Earlier what i did is , i placed a literal on the form and fill it with HTML text. All worked fine but , the text alignments of the displayed html gets overriden by the page css.
So what i want now is that, instead of literal, i place an iframe. Now at page load event , i will generate a aspx dynamically and place a literal control and fill that literal control with the html text. And then will display that aspx page in the iframe.
So i would like to know the following things:
Is this a good idea to hold heavy
text , more than 20K of chars in
memory, dynamically generate aspx
page at runtime.
If any workaround to not to inherit
the page css inside the literal
displayed.
Any other approach better than my approach.
Way to implement my approach(iframe and dynamic aspx).
--- I am using ASP.NET / C# 4.0
Loads of questions...
Thanks in advance
AmRan, if this actually is a css problem, I would first try to create separate css styles for that content and use with the first solution you did. For example, wrap your dynamic content widh
<div id="dynamicContent">
tag and place
#dynamic {}
style settings inside your css file.
I don't think the Literal control has a CssClass property so you would have to use Label instead, or some other technique.
I would try to stay away from IFrame solutions if possible.
Hope this helps.

Categories

Resources