Click here to Skip to main content
15,886,518 members
Articles / Web Development / CSS
Tip/Trick

Text/HTML Editor With ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.62/5 (13 votes)
28 Jul 2013CPOL1 min read 71.9K   7.4K   20   11
Text/HTML Editor With JQuery In ASP.Net

Image 1

Introduction

This is a text/HTML editor for ASP.NET with jQuery. ASP.NET doesn't provide any control for text editing, so this solution will be helpful for online editing on text. This solution is for people who want to format text in their applications and store in the database.

Background 

For text editing ASP.NET doesn't provide any control. So we have to use a third party tool or AJAX. In my solution I am using jQuery for text editing and the value that I get is stored in the database.

Using the code

I am using ASP.NET TextBox control for the text editor. I use the multiline mode of the textbox. In the page, Demo.css and jquery-te-1.4.0.css are added and after that jquery-te-1.4.0.min.js and jquery-1.10.2.min.js are used/added for text editor functionality.

A button control is used for getting the textbox value in HTML format to store in the database. On the click of a button the server gets a formatted data value and then it is bound to another textbox. (You could also use this data to store in the database.) In this process the JQTE blur event is helpful.

Below is the code for the text editor:

ASP.NET
<head runat="server">
    <title>Text Editor With JQuery</title>
    <link href="CSS/demo.css" rel="stylesheet" type="text/css" />
    <link href="CSS/jquery-te-1.4.0.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtEditor" TextMode="MultiLine" 
            runat="server" CssClass="textEditor"
            onblur="Test()"></asp:TextBox>
        <asp:Button ID="btnText" runat="server" 
            Text="Show Text" OnClick="btnText_Click" />
        <asp:HiddenField ID="hdText" runat="server" />
        <asp:TextBox ID="txtReText" TextMode="MultiLine" 
           runat="server" CssClass="textEditor1"></asp:TextBox>
    </div>
    </form>
</body>
<script src="JS/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="JS/jquery-te-1.4.0.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    $('.textEditor1').jqte();
    $(".textEditor").jqte({ blur: function () {
        document.getElementById('<%=hdText.ClientID %>').value = 
               document.getElementById('<%=txtEditor.ClientID %>').value;
    }
});
</script>

Code-behind:

C#
protected void btnText_Click(object sender, EventArgs e)
{
    txtReText.Text = hdText.Value;
}

Points of Interest

This is an easy way for implementing a text editor in ASP.NET and is compatible with every browsers using jQuery.

License

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


Written By
Software Developer Alitesoft
India India
Software Engineer with year of successful records serving small and mid scale .NET applications. Have a wide range of experience working in domestic client environment. I always love to learn new technologies and share with others.

Comments and Discussions

 
QuestionChrome issue for this HTML editor Pin
Member 1327052915-May-18 20:45
Member 1327052915-May-18 20:45 
GeneralMy vote of 5 Pin
Member 1352486116-Nov-17 5:13
Member 1352486116-Nov-17 5:13 
QuestionGetting Error while using same code in asp.net Pin
Yogesh Wani25-May-17 0:25
Yogesh Wani25-May-17 0:25 
QuestionOnline t-shirt designing Pin
Member 130975088-Apr-17 8:28
Member 130975088-Apr-17 8:28 
QuestionHow to seperate the tools and the text box ? Pin
Member 1124396021-Jan-16 20:56
Member 1124396021-Jan-16 20:56 
SuggestionRe: How to seperate the tools and the text box ? Pin
Vaibhav Bodake7-Jun-16 20:05
professionalVaibhav Bodake7-Jun-16 20:05 
QuestionJQTE not working with ASP.Net Pin
memrleea6-Apr-15 11:37
memrleea6-Apr-15 11:37 
GeneralMy vote of 5 Pin
Ajith_joseph5-Nov-14 6:22
Ajith_joseph5-Nov-14 6:22 
QuestionJquery text Editor Pin
shashi c18-Nov-13 22:30
shashi c18-Nov-13 22:30 
QuestionHow to add smileys and colours in text editor? Pin
syna syna12-Nov-13 2:18
syna syna12-Nov-13 2:18 
GeneralMy vote of 5 Pin
Anuj Tripathi28-Jul-13 2:59
Anuj Tripathi28-Jul-13 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.