The month part of the calendar is missing. Please find the code which i am using :
<cc1:CalendarExtender ID="txtfrom_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtfrom"
>
</cc1:CalendarExtender>
<asp:Label ID="Labeldateto" runat="server" Text="To:"></asp:Label>
<asp:TextBox ID="txtto" runat="server" Display="None"
class="Input" Height="16px" Width="136px"></asp:TextBox>
<cc1:CalendarExtender ID="txtto_CalendarExtender1" runat="server"
Enabled="True" TargetControlID="txtto"
>
</cc1:CalendarExtender>
</td>
I am getting output like
Please advice!!
please find the correct code to solve mention issue.
Related
I am trying to validate fromdate & todate textboxes in asp.net using compare validator
my script is:
<table><tr><td>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label1" runat="server" Text="Fromdate:"> </asp:Label>
<asp:TextBox ID="fromdatetxt" runat="server" Height="21px" Width="103px" ></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="fromdatetxt_CalendarExtender" runat="server"
Enabled="True" TargetControlID="fromdatetxt">
</ajaxToolkit:CalendarExtender>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text="Todate:"></asp:Label>
<asp:TextBox ID="todatetxt" runat="server" Height="21px" Width="105px" ></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="todatetxt_CalendarExtender" runat="server"
Enabled="True" TargetControlID="todatetxt">
</ajaxToolkit:CalendarExtender>
</td>
<asp:CompareValidator ID="CompareValidatorDate" runat="server" ControlToCompare="todatetxt"
ControlToValidate="fromdatetxt" Display="None" ErrorMessage="From date cannot be greaterthan To date"
operator = "LessThanEqual" Type="Date" ValidationGroup="DateValidation"></asp:CompareValidator>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" ValidationGroup="DateValidation" />
<asp:ValidationSummary ID="ValidationSummaryDate" ShowMessageBox="true" ShowSummary="False"
ValidationGroup="DateValidation" runat="server" /></td></tr></table>
</asp:Panel>
This is working fine! but I'm getting message box only when click the button. But I want to get message box the moment I clicked date in Todate in calendar control, and the textboxes must get clear. please help me out .
You can solve your problem using "Page_ClientValidate" function of javascript and "OnClientDateSelectionChanged" event of CalendarExtender.
You do not need to change your CompareValidator i.e.
<asp:CompareValidator ID="CompareValidatorDate" runat="server" ControlToCompare="todatetxt"
ControlToValidate="fromdatetxt" Display="None" ErrorMessage="From date cannot be greater than To date"
Operator="LessThanEqual" Type="Date" ValidationGroup="DateValidation"></asp:CompareValidator>
You need to add OnClientDateSelectionChanged event to your CalendarExtender as
<ajaxtoolkit:CalendarExtender id="todatetxt_CalendarExtender" runat="server" enabled="True"
targetcontrolid="todatetxt" OnClientDateSelectionChanged="validate" >
"validate" here is a javascript function. In that function you need to use "Page_ClientValidate" method of javascript as
var validate = function () {
var isValid = Page_ClientValidate("DateValidation"); //parameter is the validation group
if (!isValid) {
$("#<%= todatetxt.ClientID %>").val(''); //jquery to clear the textbox
}
}
You can modify the "validate" function as per your convenience.
I hope this helped.
Regards,
Samar
add Display="Dynamic" in validator
<asp:CompareValidator ID="CompareValidatorDate" runat="server" ControlToCompare="todatetxt"
ControlToValidate="fromdatetxt" Display="Dynamic" ErrorMessage="From date cannot be greaterthan To date"
Operator="LessThanEqual" Type="Date" ValidationGroup="DateValidation"></asp:CompareValidator>
I have bound date fields(datetime type column values) to my Grid. In the grid, the column definition is like so
My code is:
<asp:Label id="lblFromTimeForTeacher" runat="server" Text='<%# Eval("FromTime", "{0:hh/mm}")%>' Visible="false" Width="99%" />
Right now, the label text is 08-45. Could someone please tell how can I get the label text as 08:45? Thanks in advance.
Custom DateTime formatting here. In your case just change to Convert.ToDateTime(Eval("FromTime")).ToString("hh:mm")
Try the following
<asp:Label ID="lblFromTimeForTeacher" runat="server" Text='<%# Eval("FromTime", "{0:hh:mm}")%>' Visible="false" Width="99%" />
if you want in "4:05 PM" format then try the following
<asp:Label ID="lblFromTimeForTeacher" runat="server" Text='<%# Eval("FromTime", "{0:t}")%>' Visible="false" Width="99%" />
For more you can review This Link hope this will help you.
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>
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.
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.