AspdotnetCodes.com
Voted 'Best ASP.NET Host' for 2008 – DiscountASP.NET
 
Articles Subscribe for our Articles Updates
Books
Resources
Downloads
Free Tech Magazines
Archives
Softwares
Newsletter
Suggest Us
Link to Us
 MaskedEdit Extender with Date
Posted by Moderator1 on 6/12/2007 6:48:09 AM Category: AJAX
Total Views : 24227
Add to my favorites
Email to friend
  
Introduction
This article explains the MaskedEdit Extender With Date MaskType.
Description
MaskedEdit, an excellent control to use, with web applications. The MaskedEdit control is an ASP.NET AJAX extender that can be attached to a TextBox control. When using MaskedEdit the input is masked and the value is validated on the client according to the MaskType chosen. The MaskedEdit control has to be integrated with the MaskedEditValidator to verify the input. Here I’m going to explain how to use the MaskedEdit extender to take Date as input and validate it.
Step 1: Open Microsoft Visual Studio, create a new AJAX enabled web site.

Step 2: Add ScriptManager control to your Default.aspx page.

Step 3: Add a TextBox control to the page.

Step 4: Add MaskedEdit extender.

Step 5: Set the Mask property to of the extender to  "99/99/9999", MaskType property "Date", TargetControlID to "TextBox1" and PromptCharacter="_".
You can set different date format throught the Mask Property. The MaskType property plays a major role for data validation.
Step 6: Then drag and drop MaskedEditValidator into the page. Set the properties of the MaskedEditValidator as follows:

a. Set ControlExtender as "MaskedEditExtender1"
b. Set ControlToValidate as "TextBox1"
c. Set EmptyValueMessage as "Date is required"
d. Set InvalidValueMessage as "Date is invalid"
e. Set IsValidEmpty property to "False" and TooltipMessage property to "Input a Date". 

The ControlExtender property is used to integrate the MaskedEdit extender and the MaskedEdit validator. The ControlToValidate property is used to bind the input Textbox and the validator.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" Mask="99/99/9999" MaskType="Date" TargetControlID="TextBox1" PromptCharacter="_"> </cc1:MaskedEditExtender>

<cc1:MaskedEditValidator ID="MaskedEditValidator1" runat="server" ControlExtender="MaskedEditExtender1" ControlToValidate="TextBox1" EmptyValueMessage="Date is required" InvalidValueMessage="Date is invalid" IsValidEmpty="False" TooltipMessage="Input a Date"></cc1:MaskedEditValidator>
I have explained very briefly about the MaskedEdit extender. This extender can also be used to masked for various datatypes such as Number and Times. Now the task to validate the date input has been easily for most web developers.

Do you want to see this Sample, click here.
 
Viewer's Comments
Posted by jappenzeller on 6/27/2007 11:14:11 AM
Simple to the point example. Thanks.
 
Posted by Jason on 7/27/2007 7:20:42 PM
Perhaps I'm doing something wrong, but when I test this control for dates it skips to the year if I manually enter the slash after the month. I know that not every user would type the slashes, but wouldn't it be reasonable that some would?
 
Posted by miytsrda klpdq on 9/2/2007 5:13:05 AM
vrqot hioftbgs ivjwag owlyd fjzptsrg brgiwdsn cmevhsgu
 
Posted by Noluthando on 11/27/2007 4:23:45 AM
GOOD
 
Posted by arzieh on 12/3/2007 1:02:57 AM
when i chenge mask type to 9999/99/99 , maskedEdit doesnt work ,please help me
 
Posted by abcd on 12/16/2007 11:51:55 PM
On Post back the message remains even if we enter the correct date
 
Posted by Nitya on 1/5/2008 5:21:43 AM
if i want to change the date format then what i have to do in MASK property? Mask="99/99/9999" this shows mm/dd/yyyy format.. but i need dd/mm/yyyy format.. for that what i have to do?
 
Posted by veena on 2/28/2008 4:24:00 AM
this is good artical iam using the maskedit text box in the wizard control of asp.net2.0 but here the maskvalidator is not working can any body knows y the ajax control not work in the asp.net
 
Posted by Maggie on 3/7/2008 3:23:00 AM
If I use CalendarExtender, can I use the Masks controls with it ? For example:
 
Posted by Maggie on 3/7/2008 3:31:04 AM
I'll try again :) Is it possible to use MaskedEditExtender and MaskedValidator controls with the CalendarExtender control ??
 
Posted by Jor-el on 3/7/2008 11:38:49 AM
the control has the format property where you can put it in eg. dd/MM/yyyy be carefuly to write de month in capital letters,,
 
Posted by Arul on 3/21/2008 10:22:23 AM
This is very good artical . I'll try
 
Posted by Arul on 3/21/2008 10:22:51 AM
This is very good artical . I'll try
 
Posted by name on 4/22/2008 12:53:33 AM
through the given code only the date is valid but how we can validate the rage of the date through the maskededit extender, which property is used for that.
 
Posted by Ashvin on 4/23/2008 3:17:15 AM
Thanks sir, THis is very usefull.
 
Posted by Mehar on 6/17/2008 6:51:17 AM
Good one!!!
 
Posted by suryaprakash on 7/3/2008 2:28:03 AM
yours article is good .this will mostly enough to underdtand thanQ
 
Posted by suryaprakash on 7/3/2008 3:00:19 AM
When i am debugging an application i mgetting an error that is startindex lessthan 0 what it is? give me the solution
 
 Rating & Comments
A word 'Excellent' means lot to the author of this article. You can give comments about this article but not the author.
Rate this Article:   
Name:
Email Id:  
We never display your email id anywhere.
Comment/Question: Max. 500 letters
 
Sponsored by