Problem with MaskedEdit from Ajax Control Toolkit - different culture - asp.net

I want to use maskededit to make the user to do the same as in the ajax control toolkit sample for maskededit, but I need to use another format, since dates at my client is displayed as dd-MM-yyyy. I also need to put a value in there to begin with, since the date is loaded from a db (once I get this code working, that is)
Look at this sample:
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/maskededit/maskededit.aspx
I need to do the same as in the textbox labeled "Enter Date (format: 99/99/9999): "
I downloaded the sample code and changed the format to "99-99-9999" in the relevant code:
But the sample date "12-12-1999" is not displayed in the textbox. Why not?
I cant figure out, what I am doing wrong. I also tried setting the cultureName to da-DK, but it did not chance anything. I also tried Chrome, Firefox and IE7, same behaviour...
How do I fix this?
<asp:TextBox ID="TextBox5" runat="server" Width="130px" MaxLength="1" style="text-align:justify" ValidationGroup="MKE">12-12-1999</asp:TextBox>
<asp:ImageButton ID="ImgBntCalc" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png" CausesValidation="False" />
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender5" runat="server"
TargetControlID="TextBox5"
Mask="99-99-9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Date"
DisplayMoney="Left"
AcceptNegative="Left"
ErrorTooltipEnabled="True" />
<ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator5" runat="server"
ControlExtender="MaskedEditExtender5"
ControlToValidate="TextBox5"
EmptyValueMessage="Date is required"
InvalidValueMessage="Date is invalid"
Display="Dynamic"
TooltipMessage="Input a date"
EmptyValueBlurredText="*"
InvalidValueBlurredMessage="*"
ValidationGroup="MKE" />

I suposse you'll have this already fixed, but ... have you tried using UserDateFormat="DayMonthYear" ?
UserDateFormat="DayMonthYear"
<asp:TextBox ID="TextBox5" runat="server" Width="130px" MaxLength="1" style="text-align:justify" ValidationGroup="MKE">12-12-1999</asp:TextBox>
<asp:ImageButton ID="ImgBntCalc" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png" CausesValidation="False" />
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender5" runat="server"
TargetControlID="TextBox5"
Mask="99-99-9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Date"
DisplayMoney="Left"
AcceptNegative="Left"
ErrorTooltipEnabled="True" **UserDateFormat="DayMonthYear"** />
<ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator5" runat="server"
ControlExtender="MaskedEditExtender5"
ControlToValidate="TextBox5"
EmptyValueMessage="Date is required"
InvalidValueMessage="Date is invalid"
Display="Dynamic"
TooltipMessage="Input a date"
EmptyValueBlurredText="*"
InvalidValueBlurredMessage="*"
ValidationGroup="MKE" />

I use ValidationExpression in MaskedEditValidator replace userDateFormat type Date dd/MM/yyy is very good.
This is :
ValidationExpression="(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/((20[0-9][0-9])|(19[0-9][0-9])))|((29\/02\/(19|20)(([02468][048])|([13579][26]))))"
And in MaskedEditExtender put MaskType="none".
Validate ok.

<asp:TextBox ID="TextBox5" runat="server" Width="130px" MaxLength="10" style="text-align:justify" ValidationGroup="MKE" Text="12-12-1999"></asp:TextBox>
I am wondering if you move the text to the actual text attribute, if that would make a difference... I don't have the most recent version of AjaxToolkit other wise I would try it my self... Oh I just noticed is your max length really set to one or is that a copy and paste error? That would cause problems too.

Related

asp.Net ValidationGroup validating correctly except on Enter key

I've seen a variety of questions here that are very close to this issue but none which seem to fit this specific scenario.
Description:
I have ID and Password fields with a Log On button in the Master page. These are in the "LoginValidationGroup" and they work fine.
Now, in the Default.aspx, I have an email TextBox and submit button that are in the "NotifyMeValidation" group, and they also work, BUT not if you hit the enter key rather than the submit button. The Submit button works fine - Enter key ... not so much.
The Enter key causes the validation to occur on the LoginValidationGroup, even though the TextBox is set to CausesValidation="true", and it is in the NotifyMeValidation group.
I guarantee people are going to enter an email in that box and hit Enter. I would!!! And when they do, they're going to see a callout balloon at the top telling them the User ID is required.
What's my error here? If I need to post the actual code I can do so.
Actually, let me just go ahead and do that.
From the Default.aspx:
<asp:RequiredFieldValidator
runat="server"
ValidationGroup="NotifyMeValidation"
ID="EmailRequiredValidator"
ControlToValidate="SenderEmailTextBox"
ErrorMessage="Email is Required"
Display="None" />
<ajaxToolkit:ValidatorCalloutExtender
runat="Server"
PopupPosition="Left"
ID="EmailRequiredValidatorExtender"
Width="185px"
TargetControlID="EmailRequiredValidator"
WarningIconImageUrl="/Images/warning.gif" />
<asp:Label ID="SenderEmailLabel" runat="server" ssociatedControlID="SenderEmailTextBox" EnableViewState="false" Text="Email:"></asp:Label>
<asp:TextBox ID="SenderEmailTextBox" runat="server" ValidationGroup="NotifyMeValidation" Width="350" BackColor="#cccccc" CausesValidation="true"></asp:TextBox>
<br /><br />
<asp:Button ID="SubmitButton" runat="server" ValidationGroup="NotifyMeValidation" EnableViewState="false" CssClass="submit" Text="Send" CausesValidation="true" OnClick="btnSubmit_Click" />
From the Master page:
<asp:Label CssClass="LoginHeading" ID="UserNameLabel" runat="server" AssociatedControlID="UserNameTextbox">UserName: </asp:Label>
<asp:TextBox CssClass="LoginTextBox" ID="UserNameTextbox" runat="server" ValidationGroup="LoginValidation" CausesValidation="True"></asp:TextBox>
<asp:Label CssClass="LoginHeading" ID="PasswordLabel" runat="server" AssociatedControlID="PasswordTextbox">Password: </asp:Label>
<asp:TextBox CssClass="LoginTextBox" ID="PasswordTextBox" runat="server" TextMode="Password" ValidationGroup="LoginValidation" CausesValidation="True"></asp:TextBox>
<asp:Button CssClass="LoginHeading" ID="LoginButton" runat="server" Text="Button" CommandName="Login" ValidationGroup="LoginValidation" CausesValidation="True" onclick="LoginButton_Click" />
And the Master page validators...
<asp:RequiredFieldValidator runat="server" ID="UIDRequired"
ValidationGroup="LoginValidation"
ControlToValidate="UserNameTextbox"
Display="None"
ErrorMessage="<b>Required Field Missing</b><br />A User ID is required." />
<ajaxToolkit:ValidatorCalloutExtender
runat="Server"
ID="UIDValidationExtender"
PopupPosition="Left"
Width="185px"
TargetControlID="UIDRequired"
WarningIconImageUrl="/Images/warning.gif" />
<asp:RequiredFieldValidator runat="server" ID="PWRequired"
ValidationGroup="LoginValidation"
ControlToValidate="PasswordTextbox"
Display="None"
ErrorMessage="<b>Required Field Missing</b><br />A password is required." />
<ajaxToolkit:ValidatorCalloutExtender
runat="Server"
ID="PWValidationExtender"
PopupPosition="Left"
TargetControlID="PWRequired"
Width="185px"
WarningIconImageUrl="/Images/warning.gif" />
<asp:CustomValidator
runat="server"
Display="None"
ValidationGroup="LoginValidation"
ID="CustomUserExistsValidator"
ControlToValidate="UserNameTextbox"
ErrorMessage="<b>Invalid UserID!</b><br />User ID doesn't exist. Please try again.<br />"
OnServerValidate="CustomCheckUserExists"/>
<ajaxToolkit:ValidatorCalloutExtender
runat="server"
PopupPosition="Left"
ID="UserIDCalloutExtender"
TargetControlID="CustomUserExistsValidator"
Width="185px"
WarningIconImageUrl="/Images/warning.gif" />
<asp:CustomValidator
runat="server"
ID="CustomPWValidator"
Display="None"
ValidationGroup="LoginValidation"
ControlToValidate="PasswordTextbox"
ErrorMessage="<b>Invalid Password!</b><br />Please try again.<br />"
OnServerValidate="CustomValidatePassword"/>
<ajaxToolkit:ValidatorCalloutExtender
runat="server"
PopupPosition="Left"
ID="PWCalloutExtender"
TargetControlID="CustomPWValidator"
Width="185px"
WarningIconImageUrl="/Images/warning.gif" />
<asp:CustomValidator
runat="server"
ID="CustomUserApprovedValidator"
Display="None"
ValidationGroup="LoginValidation"
ControlToValidate="UserNameTextbox"
ErrorMessage="<b>Approval Error!</b><br />This UserID exists, but is not yet approved.<br />"
OnServerValidate="CustomCheckUserApproved"/>
<ajaxToolkit:ValidatorCalloutExtender
runat="server"
PopupPosition="Left"
ID="UserApprovedCalloutExtender"
TargetControlID="CustomUserApprovedValidator"
Width="185px"
WarningIconImageUrl="/Images/warning.gif" />
Try adding an <asp:Panel> around each set of controls and setting the DefaultButton property to the ID of the button you want to click when the users hits Enter.
Just to explain what is happening here, the aspx's default button is being fired when you press enter on the textbox. To handle this you could you could fire some jQuery code when the enter key is clicked on the textbox, this code will then perform the click on the specific button that you require. Check this

asp:MaskedEditExtender stops validator working

I have a RequiredFieldValidator. The code is below:
<asp:TextBox runat="server" ID="phone" MaxLength="10" Columns="10"
Width="90px"></asp:TextBox>
<asp:MaskedEditExtender ID="phone_MaskedEditExtender" runat="server" CultureAMPMPlaceholder=""
CultureCurrencySymbolPlaceholder="" CultureDateFormat="" CultureDatePlaceholder=""
CultureDecimalPlaceholder="" CultureThousandsPlaceholder="" CultureTimePlaceholder=""
Enabled="True" TargetControlID="phone" Mask="(999)999-9999" ClearMaskOnLostFocus="False">
</asp:MaskedEditExtender>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidatorPhone" ControlToValidate="phone"
ErrorMessage="Phone is required." Display="Dynamic" InitialValue="" />
If I remove the asp:MaskedEditExtender, the RequiredFieldValidator functions as expected. Otherwise it seems the validator loses its functionality.
Why?
Thanks.
Your MaskedEditExtender isn't doing anything but declaring a mask, and putting itself in the place of the value of your input.
All those Cultures are not needed in the case of a phone number.
What is the validation expression?
The whole point of the MaskedExtender is to control the input type. If you are using ASP you can do this by pulling from database and restricting the max length of the field.
Here is an example.
<cc1:MaskedEditExtender ID="MaskedEditExtender1"
runat="server"
TargetControlID="txtClientLookupValue"
Mask="999999-9999"
ClearMaskOnLostFocus="false">
</cc1:MaskedEditExtender>
<cc1:MaskedEditValidator ID="MaskedEditValidator1"
ControlExtender="MaskedEditExtender1"
runat="server"
ControlToValidate="txtClientLookupValue"
IsValidEmpty="True"
InvalidValueMessage="INVALID"
ValidationExpression="^[2-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$"
Display="Dynamic">
</cc1:MaskedEditValidator>
And here is a reference:
MaskedEditExtenderLinkASP
Good Luck.
Here is how I do phone numbers in ASP.NET (mask and validation). Just trying to help!
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="txb_HomePhoneNumb"
Cssclass="BoxStyleHireAppCityStateZip" runat="server"
Width="175" MaxLength="12">
</asp:TextBox>
<%--MaskedEditExtender Created with: ASP.NET AJAX Control
Toolkit: https://ajaxcontroltoolkit.codeplex.com--%>
<cc1:MaskedEditExtender ID="MaskedEditExtenderHomePhoneNumb"
runat="server"
TargetControlID="txb_HomePhoneNumb"
ClearMaskOnLostFocus ="false"
MaskType="None"
Mask="(999) 999-9999"
MessageValidatorTip="true"
InputDirection="LeftToRight"
ErrorTooltipEnabled="True"
/>
<asp:RegularExpressionValidator runat="server"
ControlToValidate="txb_HomePhoneNumb" style="color:red;"
CssClass="display-next"
ErrorMessage="*Not a valid phone number!"
ValidationExpression="^\D?(\d{3})\D?\D?(\d{3})\D?
(\d{4})$" Font-Size="Medium">
</asp:RegularExpressionValidator>
</div>

Rangevalidator for calendar extender entries gives problems in safari

I have the following scenario:
arrival and departure dates have to be selected on a form, through 2 textboxes with a calendar extender each.
I validate the entries to check that no date before today is selected and to check that the departure is after the arrival. I used a rangevalidator and a comparevalidator.
In IE, Firefox and Opera it is working fine, in Safari (on windows) however both the validators go off even on entries that should be accepted.
It makes me suspect that the date format dd/MM/yyyy causes trouble for Safari.
(the dd/MMMM/yyyy also gave the same troubles in the other browsers, probably due to the dependency on UIculture)
The code is:
<tr>
<td>
<asp:TextBox ID="txtArrive" runat="server"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="txtArriveWatermarkExt" runat="server"
Enabled="True" TargetControlID="txtArrive" WatermarkText="arrival date">
</cc1:TextBoxWatermarkExtender>
<cc1:CalendarExtender ID="ArriveCalendarExt" runat="server"
CssClass="MyCalendar" Enabled="True" Format="dd/MM/yyyy"
TargetControlID="txtArrive">
</cc1:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtArrive" ErrorMessage="please select arrival date"
Text="*" ValidationGroup="date" Display="none"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ErrorMessage="please make sure that your arrival date is later than today and not later than a year from now"
ControlToValidate="txtArrive" Type="Date" ValidationGroup="date" Text="*"></asp:RangeValidator>
</td>
<td>
<asp:TextBox ID="txtDepart" runat="server"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="txtDepartWatermarkExt" runat="server"
Enabled="True" TargetControlID="txtDepart" WatermarkText="departure date">
</cc1:TextBoxWatermarkExtender>
<cc1:CalendarExtender ID="DepartCalendarExt" CssClass="MyCalendar" runat="server" Enabled="True"
Format="dd/MM/yyyy" TargetControlID="txtDepart">
</cc1:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtDepart" ErrorMessage="Please select departure date"
Text="*" ValidationGroup="date"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator2" runat="server"
ControlToCompare="txtDepart" ControlToValidate="txtArrive"
ErrorMessage="your departure date has to be later than your arrival date"
Operator="LessThan" Type="Date" Text="*" ValidationGroup="date"></asp:CompareValidator>
</td>
<td>
</td>
</tr>
The range validator gets its values in code behind on Page_load
RangeValidator1.MinimumValue = DateTime.Now.AddDays(1).ToShortDateString();
RangeValidator1.MaximumValue = DateTime.Now.AddMonths(12).ToShortDateString();
Does anybody have any suggestions on how to solve this problem with safari?
set format property to Format="dd/MM/yyyy" of calender extender

date validation in asp.net

is this following a proper date validation fn
<asp:TextBox ID="date" Width="80px" MaxLength="10" runat="server" />
</td>
<td>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="date"
ErrorMessage="date. " ValidationExpression="^(\d{4})(\d{2})(\d{2})$" Display="Static" Font-Names="Arial"
Font-Size="11" runat="server">
enter a valid date formate
</asp:RegularExpressionValidator>
I believe this would be a better approach, use what's built-in:
<asp:TextBox ID="date" Width="80px" MaxLength="10" runat="server" />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="date" ErrorMessage="* Enter a valid date"
Operator="DataTypeCheck" Type="Date" />
The key settings are Operator and Type.
Note if you have to consider multiple cultures and such, this becomes a much more involved question, hopefully that isn't the case.

asp.net ajax MaskedEditExtender

hi i'm using the maskeditexdenter for getting money value ,the problem is when the input is given it takes it from left to right i want it to take it from right to left. the code is
<asp:TextBox ID="txt_actual_ConveyanceCharges" CssClass="Controls" runat="server"></asp:TextBox>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="txt_actual_ConveyanceCharges" Mask="99,999,999.99" MaskType=Number InputDirection="RightToLeft"/>
Hai anand Try this,
<ajaxToolkit:MaskedEditExtender runat="server"
TargetControlID="UrTxtBoxID"
Mask="9,999,999.99"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Number"
InputDirection="RightToLeft"
AcceptNegative="Left"
DisplayMoney="Left"
/>

Resources