473,503 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTML in User Comments

I have a repeater where I output user comments (255 char limit).

I want to give the user the ability to add <i>italic</i> and <b>bold</b> font using standard HTML tags.

I changed the repeater to have a label with id=RepeaterCommentText. I then registered the ItemDataBound event to be handled by CommentBound (which has the appropriate parameters). On Comment Entry I change the tags to have square braces (ex. "<b>" to "[b]"). In CommentBind I change the specially formatted tags back to HTML (this code is at home and I’m not. The actual code does work, I know there are probably some minor errors in this 1 block, but you get the idea).

// code in CommentBind
Label lbl = (Label)e.FindControl("RepeaterCommentText");
String text = lbl.text.Replace("", "<b>");
text = text.Replace("
", "</b>");

in the code that handles comment entry I do the reverse (replace "<b>" with "").

Everything works fine. However, if the user enters text like the following:

Text:
<i>Italic
<b>bold

Then the rest of the page becomes bold and italic, as there are no closing tags.
What I thought about doing on comment entry was

// keep the normal tags
CommentText = CommentText.Replace("<b>", "<b>");
CommentText = CommentText.Replace("</b>", "</b>
");
int startTags, endTags; // counters
startTags = 0; endTags = 0; // init counts

// count opening tags
while (CommentText.IndexOf("<b>") != -1)
{
CommentText.Remove(CommentText.IndexOf("<b>"), 3);
startTags++;
}

//count closing tags
while (CommentText.IndexOf("<b>") != -1)
{
CommentText.Remove(CommentText.IndexOf("</b>"), 4);
endTags++;
}

// if the user failed to enter a few closing tags, add them
if ( startTags > endTags)
{
while (startTags > endTags)
{
CommentText += "
"; endTags++;
}
}

// if the user failed to enter a few opening tags, add them
if ( endTags > startTags )
{
while ( endTags > startTags )
{
CommentText = "[b]" + CommentText; startTags++;
}
}

I don't like this method though as it seems like way too much code for a simple task.

Any suggestions for another approaches?

Thanks,
Ryan
Nov 16 '05 #1
2 1248
Hi Ryan,

There are better solution for this, take a look at this control :
http://www.gotdotnet.com/community/usersamples/

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ryan Riddell" <Ry*********@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
I have a repeater where I output user comments (255 char limit).

I want to give the user the ability to add <i>italic</i> and <b>bold</b> font using standard HTML tags.
I changed the repeater to have a label with id=RepeaterCommentText. I then registered the ItemDataBound event to be handled by CommentBound (which has
the appropriate parameters). On Comment Entry I change the tags to have
square braces (ex. "<b>" to "[b]"). In CommentBind I change the specially
formatted tags back to HTML (this code is at home and I'm not. The actual
code does work, I know there are probably some minor errors in this 1 block,
but you get the idea).
// code in CommentBind
Label lbl = (Label)e.FindControl("RepeaterCommentText");
String text = lbl.text.Replace("", "<b>");
text = text.Replace("
", "</b>");

in the code that handles comment entry I do the reverse (replace "<b>" with "").
Everything works fine. However, if the user enters text like the following:
Text:
<i>Italic
<b>bold

Then the rest of the page becomes bold and italic, as there are no closing tags. What I thought about doing on comment entry was

// keep the normal tags
CommentText = CommentText.Replace("<b>", "<b>");
CommentText = CommentText.Replace("</b>", "</b>
");
int startTags, endTags; // counters
startTags = 0; endTags = 0; // init counts

// count opening tags
while (CommentText.IndexOf("<b>") != -1)
{
CommentText.Remove(CommentText.IndexOf("<b>"), 3);
startTags++;
}

//count closing tags
while (CommentText.IndexOf("<b>") != -1)
{
CommentText.Remove(CommentText.IndexOf("</b>"), 4);
endTags++;
}

// if the user failed to enter a few closing tags, add them
if ( startTags > endTags)
{
while (startTags > endTags)
{
CommentText += "
"; endTags++;
}
}

// if the user failed to enter a few opening tags, add them
if ( endTags > startTags )
{
while ( endTags > startTags )
{
CommentText = "[b]" + CommentText; startTags++;
}
}

I don't like this method though as it seems like way too much code for a simple task.
Any suggestions for another approaches?

Thanks,
Ryan

Nov 16 '05 #2
Hi again,

Sorry , I sent you the wrong link, this is the correct one:
http://msdn.microsoft.com/library/de...tml_editor.asp
Sorry for that :)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ryan Riddell" <Ry*********@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
I have a repeater where I output user comments (255 char limit).

I want to give the user the ability to add <i>italic</i> and <b>bold</b> font using standard HTML tags.
I changed the repeater to have a label with id=RepeaterCommentText. I then registered the ItemDataBound event to be handled by CommentBound (which has
the appropriate parameters). On Comment Entry I change the tags to have
square braces (ex. "<b>" to "[b]"). In CommentBind I change the specially
formatted tags back to HTML (this code is at home and I'm not. The actual
code does work, I know there are probably some minor errors in this 1 block,
but you get the idea).
// code in CommentBind
Label lbl = (Label)e.FindControl("RepeaterCommentText");
String text = lbl.text.Replace("", "<b>");
text = text.Replace("
", "</b>");

in the code that handles comment entry I do the reverse (replace "<b>" with "").
Everything works fine. However, if the user enters text like the following:
Text:
<i>Italic
<b>bold

Then the rest of the page becomes bold and italic, as there are no closing tags. What I thought about doing on comment entry was

// keep the normal tags
CommentText = CommentText.Replace("<b>", "<b>");
CommentText = CommentText.Replace("</b>", "</b>
");
int startTags, endTags; // counters
startTags = 0; endTags = 0; // init counts

// count opening tags
while (CommentText.IndexOf("<b>") != -1)
{
CommentText.Remove(CommentText.IndexOf("<b>"), 3);
startTags++;
}

//count closing tags
while (CommentText.IndexOf("<b>") != -1)
{
CommentText.Remove(CommentText.IndexOf("</b>"), 4);
endTags++;
}

// if the user failed to enter a few closing tags, add them
if ( startTags > endTags)
{
while (startTags > endTags)
{
CommentText += "
"; endTags++;
}
}

// if the user failed to enter a few opening tags, add them
if ( endTags > startTags )
{
while ( endTags > startTags )
{
CommentText = "[b]" + CommentText; startTags++;
}
}

I don't like this method though as it seems like way too much code for a simple task.
Any suggestions for another approaches?

Thanks,
Ryan

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1888
by: Andrew Poulos | last post by:
While this works on IE 6: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>aiff</title> <meta http-equiv="Content-Type"...
38
7094
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } ...
24
2803
by: chri_schiller | last post by:
I have a home-made website that provides a free 1100 page physics textbook. It is written in html and css. I recently added some chinese text, and since that day there are problems. The entry...
16
2012
by: graham.reeds | last post by:
I am updating a website that uses a countdown script embedded on the page. When the page is served the var's are set to how long the countdown has left in minutes and seconds, but the rest of the...
2
2184
by: Nick Gilbert | last post by:
Hi I have a number of pages where it is valid for the user to enter HTML. On these pages, I have turned off RequestValidation ("ValidateRequest = false" in the page directive) so that the...
1
2072
by: bidllc | last post by:
I'm working on a minor bug from an open source bug tracking system (bugtracket.net). It's a great app, but I don't want to bother the creator any more than I have to, so I thought I'd pose the...
6
12965
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
41
4347
by: deko | last post by:
A web page can be created using either strict or transitional HTML. The DOCTYPE for strict is: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> And...
6
2508
by: Shawn | last post by:
Hello: I have the following code in a PHP file. An HTML form passes user comment data to the PHP, which then appends the user comments to the end of the HTML file on which the form is located....
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.