How To use RadEditor and how to Suppress the built in message of maxlength validation.


In this article i am going to explain RadEditor control. Which is a third party control known as Telerik controls. It has a inbuilt functionality of checking the maxlength and firing validation message if it voilates.We will also see how we can suppress that message using client side or server side validation. Find how to use RadEditor and how to Suppress the built in message of maxlength validation.

Learn how to use RadEditor & how to Suppress the built in message of maxlength validation


RadEditor is a third Party control. It provides many options for editing of text that we entered like changing background and fore color, size, format etc.

Using it requires just a RasScriptManager control or ScriptManager.And then use RadEditor control.


<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<telerik:RadEditor ID="radeditor" runat="server">
</telerik:RadEditor>


Now if you want to suppress the inbuilt message of MaxLength validation we can use below code.

for that first add a button on whose click event write below code:

protected void Button1_Click(object sender, EventArgs e)
{
string body = radeditor.Content.Trim();

if (body.Length > 10)
{
Response.Write("<script> alert('Error: Comments can not exceed 1250 characters!')</script>");

}
}


If you dont want to count the spaces use below code:


protected void Button1_Click(object sender, EventArgs e)
{
string body = radeditor.Content.Trim();
body = body.Replace(" ", "");
if (body.Length > 10)
{
Response.Write("<script> alert('Error: Comments can not exceed 1250 characters!')</script>");

}
}




If you want to do it client side using client side validation use below javascript:

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function chec(event) {

var editor = $find("<%=radeditor.ClientID%>");

var a = editor.get_text().length;


if (a > 10) {
alert('hi');
event.returnValue = false;

}
}
</script>
</telerik:RadCodeBlock>


And use butotn code like:

<asp:LinkButton runat="server" CssClass="form_button" ID="lbtnSave" OnClick="lbtnSave_Click"
OnClientClick="return chec(event)"></asp:LinkButton>


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: