Click here to Skip to main content
15,888,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How to prevent storing the Div tags in my data base while i am using Asp.net Text box?
Please give solution for this issue...
Posted
Updated 30-Jun-13 23:06pm
v2
Comments
abhinavpratap 1-Jul-13 5:10am    
Show some code of saving the textbox text to database.
Ganeshh2 1-Jul-13 5:13am    
cmd.Parameters.Add(new SqlParameter("@q_desc", SqlDbType.VarChar, 8000)).Value = ques;

where "ques" is the string which is entered into my Multi line text box. but when iam clicking enter button from my keyboard it is going to the next div in textbox.

hi Ganesh,
As you are using htmleditor extender. So check this link
http://forums.asp.net/t/1789784.aspx/1[^]

Also what you want to save in db is still not clear.
As if you save only string text in db removing html tags, then it will cause problem later on, if you want to display the saved text in the htmleditorextender.

Still you want to save only string text removing HTML tags.
Check this link - http://stackoverflow.com/questions/785715/how-can-i-strip-html-tags-from-a-string-in-asp-net?lq=1[^]

A better approach would be - Saving the html text as it is but by HttpUtility.HtmlEncode()
so later it gets displayed in editor as it is with HttpUtility.HtmlDecode()

And where you need only text no html tags, make a method which returns string text by passing html extender text, with use of regex like above link(save only string text removing HTML tags) and use that method.

C#
public string HTMLToString(string htmlText)
{
 string strText =string.Empty;
if(!string.IsNullOrEmpty(htmlText))
{
 strText = System.Text.RegularExpressions.Regex.Replace(HttpUtility.HtmlDecode(htmlText), @"<[^>]*(>|$)",string.Empty);
strText = System.Text.RegularExpressions.Regex.Replace(strText , @"[\s\r\n]+",string.Empty);
}
 return strText;
}
 
Share this answer
 
Comments
Ganeshh2 2-Jul-13 3:39am    
Hi abhinavpratap,
Thanks for your solution.
You can use regular expression to replace the
tag. Try this:
string result = Regex.Replace(YourString, @"</?DIV>", "");


Also see some similar threads:
Remove text enclosed in an div tag using C# Regex[^]
Removing <div> from text file?[^]

--Amit
 
Share this answer
 
v2
Comments
Ganeshh2 1-Jul-13 5:33am    
Thank you Amit,

I will check your links and try.
_Amy 1-Jul-13 5:37am    
Welcome. :)
The multiline asp.net textbox's text will not make div tag on enter click of keyboard.
I just tested a default application and it returns "line1\r\nline2\r\nline3" as string, where \r\n (carriage return and newline) are enter clicks.
So there must be some code replacing carriage return and newline characters to div tags in your code.

Either find and comment or remove that code
or replace the div tag from string as suggested by _amy.
 
Share this answer
 
v2
Comments
Ganeshh2 1-Jul-13 7:59am    
Hi abhinavpratap,
Thank you for your valuable reply. In normal Asp.net Textbox it is working fine as you said. But I am using Ajax Html editor extender with Asp.net Textbox. In that it is making div tags.
bbirajdar 1-Jul-13 10:07am    
Kind request to you to provide complete information in the question so that other people who want to help you should not waste their time in providing you solutions based on your incomplete information
Ganeshh2 2-Jul-13 1:01am    
ok.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900