Tuesday, October 18, 2011

How to use MaskedEditValidator in asp.net ajax


UsingMaskedEditValidator.aspx
  1. <%@ Page Language="C#" AutoEventWireup="true" %>  
  2.   
  3. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>  
  4.   
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  6. <script runat="server">  
  7.     protected void Button1_Click(object sender, EventArgs e)  
  8.     {  
  9.         Label1.Text = "You submitted date: ";  
  10.         Label1.Text += Convert.ToDateTime(TextBox1.Text).ToLongDateString();  
  11.     }  
  12. </script>  
  13. <html xmlns="http://www.w3.org/1999/xhtml" >  
  14. <head id="Head1" runat="server">  
  15.     <title>Ajax MaskedEditValidator - How to use MaskedEditValidator in asp.net ajax</title>  
  16. </head>  
  17. <body>  
  18.     <form id="form1" runat="server">  
  19.     <div>  
  20.         <h2 style="color:IndianRed; font-style:italic;">Ajax Control Toolkit Example: Using MaskedEditValidator</h2>  
  21.         <hr width="600" align="left" color="Salmon" />  
  22.         <asp:ScriptManager   
  23.             ID="ScriptManager1"  
  24.             runat="server"  
  25.             >  
  26.         </asp:ScriptManager>  
  27.         <br /><br />  
  28.         <asp:Label   
  29.             ID="Label1"  
  30.             runat="server"  
  31.             ForeColor="DeepPink"  
  32.             Font-Size="Large"  
  33.             Font-Italic="true"  
  34.             Font-Bold="true"  
  35.             >  
  36.         </asp:Label>  
  37.         <br /><br />  
  38.         <asp:Label   
  39.             ID="Label2"  
  40.             runat="server"  
  41.             Text="Meeting Date [mm/dd/yyyy] "  
  42.             ForeColor="DarkSeaGreen"  
  43.             Font-Bold="true"  
  44.             >  
  45.         </asp:Label>  
  46.         <asp:TextBox   
  47.             ID="TextBox1"  
  48.             runat="server"  
  49.             BackColor="DarkSeaGreen"  
  50.             Font-Bold="true"  
  51.             ForeColor="Snow"  
  52.             >  
  53.         </asp:TextBox>  
  54.         <cc1:MaskedEditExtender   
  55.             ID="MaskedEditExtender1"  
  56.             runat="server"  
  57.             TargetControlID="TextBox1"  
  58.             Mask="99/99/9999"  
  59.             MaskType="Date"  
  60.             MessageValidatorTip="true"  
  61.             >  
  62.         </cc1:MaskedEditExtender>  
  63.         <cc1:MaskedEditValidator   
  64.             ID="MaskedEditValidator1"  
  65.             runat="server"  
  66.             ControlToValidate="TextBox1"  
  67.             ControlExtender="MaskedEditExtender1"  
  68.             IsValidEmpty="false"  
  69.             EmptyValueMessage="Input date"  
  70.             InvalidValueMessage="inputted date not valid"  
  71.             >  
  72.         </cc1:MaskedEditValidator>  
  73.         <br /><br />  
  74.         <asp:Button   
  75.             ID="Button1"  
  76.             runat="server"  
  77.             Text="Submit Next Meeting Date"              
  78.             Font-Bold="true"  
  79.             ForeColor="SaddleBrown"  
  80.             OnClick="Button1_Click"  
  81.             Height="40"  
  82.             />  
  83.     </div>  
  84.     </form>  
  85. </body>  
  86. </html>