Creating Text Editor Using ASP.Net and jQuery


This article explains how to create a Text Editor using ASP.NET and jQuery.
Step 1
First of all, add a new application to your Visual Studio and name it "ASPNet Text Editor".
Now in this application we will add two TextBoxes, one Button and a Hidden Field.
  1. <asp:TextBox ID="TextBox1" TextMode="MultiLine" runat="server" CssClass="textBox" onblur="Test()"></asp:TextBox>  
  2. <asp:Button ID="Button1" runat="server" Text="Show it Below" />  
  3. <asp:HiddenField ID="hdField" runat="server" />  
  4. <asp:TextBox ID="textBox2" TextMode="MultiLine" runat="server" CssClass="textBox2"></asp:TextBox> 
Step 2
As you can see, I provided the CSS Classes in the code above. That's because I had already created the CSS and then I passed its name to these controls.
You can check the CSS code by downloading the Zip Code provided at the start of the article.
After creating the CSS, provide their reference in the Head section of the page like this:
  1. <link href="CSS/demo.css" rel="stylesheet" type="text/css" />  
  2. <link href="CSS/demo2.css" rel="stylesheet" type="text/css" /> 
Step 3
Now you need to add two jQuery files to your application named jquery-1.10.2.min.js and jquery-te-1.4.0.min.js.
You will get these files from my application code provided in the Zip.
Provide this code after the Body tag:
  1. <script src="JS/jquery-1.10.2.min.js" type="text/javascript"></script>  
  2. <script src="JS/jquery-te-1.4.0.min.js" type="text/javascript"></script>  
  3. <script language="javascript" type="text/javascript">  
  4. $('.textEditor1').jqte();  
  5. $(".textBox2").jqte({  
  6.      blur: function() {  
  7.           document.getElementById('<%=hdField.ClientID %>').value = document.getElementById('<%=txtBox2.ClientID %>').value;  
  8.      }  
  9. });  
  10. </script> 
Step 4
On the Button click pass this code:
  1. protected void btnText_Click(object sender, EventArgs e) {    
  2.     textbox2.Text = hdFieldt.Value;    
  3. }   
Now your complete code will look like this:
  1. <head runat="server">  
  2.     <title>ASP.NET Text Editor</title>  
  3.     <link href="CSS/demo.css" rel="stylesheet" type="text/css" />  
  4.     <link href="CSS/demo2.css" rel="stylesheet" type="text/css" />  
  5. </head>  
  7. <body>  
  8.     <form id="Editor" runat="server">  
  9.         <div>  
  10.             <asp:TextBox ID="TextBox1" TextMode="MultiLine" runat="server" CssClass="textBox" onblur="Test()"></asp:TextBox>  
  11.             <asp:Button ID="Button1" runat="server" Text="Show it Below" />  
  12.             <asp:HiddenField ID="hdField" runat="server" />  
  13.             <asp:TextBox ID="textBox2" TextMode="MultiLine" runat="server" CssClass="textBox2"></asp:TextBox>  
  14.         </div>  
  15.     </form>  
  16. </body>  
  17. <script src="JS/jquery-1.10.2.min.js" type="text/javascript"></script>  
  18. <script src="JS/jquery-te-1.4.0.min.js" type="text/javascript"></script>  
  19. <script language="javascript" type="text/javascript">  
  20. $('.textEditor1').jqte();  
  21. $(".textBox2").jqte({  
  22.     blur: function() {  
  23.         document.getElementById('<%=hdField.ClientID %>').value = document.getElementById('<%=txtBox2.ClientID %>').value;  
  24.     }  
  25. });  
  26. </script> 
Now write something and modify it according to your needs.