Monday, August 13, 2012

Ajax Editor Validation

Code Snippet
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
  2.  
  3. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor"
  4.     TagPrefix="cc1" %>
  5.  
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7.  
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head id="Head1" runat="server">
  10.     <title></title>
  11.  
  12.  
  13.     <script type="text/javascript">
  14.         function Validation() {
  15.             var text = document.getElementById('txt1').value;
  16.             if (text == "") {
  17.                 alert('Name Cannot be empty');
  18.                 document.getElementById('txt1').focus();
  19.                 return false;
  20.             }
  21.  
  22.             test()
  23.         }
  24.  
  25.         function test() {
  26.             var a = $find("Editor1");
  27.             var value = a.get_content();
  28.             if (value == "") {
  29.                 $get("result").innerHTML = "Editor's content is empty";
  30.                 alert('Editor Cannot be empty');
  31.                
  32.                 return false;
  33.             }
  34.         }
  35.  
  36.  
  37.     </script>
  38.  
  39.  
  40. </head>
  41. <body>
  42.     <form id="form1" runat="server">
  43.     <div>
  44.         <asp:ScriptManager ID="ScriptManager1" runat="server" />
  45.  
  46.         Name:<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
  47.         <br />
  48.  
  49.         <cc1:Editor ID="Editor1" runat="server" Width="300" Height="300" ValidationGroup="Editor" />
  50.         <br />
  51.         <span id="result"></span>
  52.         <br />
  53.         <asp:Button ID="Button1" runat="server" Text="Submit" OnClientClick="return Validation();"
  54.             CausesValidation="true" ValidationGroup="Editor" />
  55.     </div>
  56.     </form>
  57. </body>
  58. </html>

0 comments:

Post a Comment