i have added an extender to the text box to select date. The date it shows the number of the corresponing month. is there any way to get the month name instead of the month number? for eg i get as 04-04-13 i want it as 04-Apr-13. Thanks in advance
the code i have is
<asp:TextBox ID="txtInvDate" runat="server" Height="21px" Width="88px"
ontextchanged="txtInvDate_TextChanged" AutoPostBack="True"></asp:TextBox>
<asp:CalendarExtender ID="txtInvDate_CalendarExtender"
runat="server" TargetControlID="txtInvDate" Format="dd-MM-yyyy">
</asp:CalendarExtender>
You could try following format:
<asp:CalendarExtender ID="txtInvDate_CalendarExtender" runat="server" TargetControlID="txtInvDate"
Format="dd-MMM-yyyy" >
</asp:CalendarExtender>
Custom Date and Time Format Strings
particularly: The "MMM" Custom Format Specifier
Note that it depends on the current culture on the server.
Related
I'm having a situation where i'm having a Calendar control in my page and when user selects a date it should check whether date selected is greater than today's date.
I tried a lot and Googled it as well, but in every place they are taking value using a textbox and i want the same to be done with a Calendar control.
Contrary to popular belief, you actually don't need any C# code to get this done! All you need is some extenders and validators on your date textbox. So let's say I had two textboxes -- one named txtStartDt and one named txtEndDate; this is how the extensions for them would be placed:
// Start Date
<asp:TextBox ID="txtStartDt" runat="server" CssClass="textboxint" /> // the main control itself
<ajax:CalendarExtender ID="calStartDt" runat="server" PopupPosition="BottomRight"
TargetControlID="txtStartDt" /> // allows the control to behave like a calendar picker
<asp:CompareValidator ID="CVStartDt" runat="server" Type="Date" Operator="LessThan"
ErrorMessage="Start Date must come before the End Date" ValidationGroup="ReportDate"
ControlToValidate="txtStartDt" ControlToCompare="txtEndDt" Display="None" /> // THIS is the main solution to your problem
<ajax:ValidatorCalloutExtender ID="VCEStartDt" runat="server" TargetControlID="CVStartDt"
HighlightCssClass="valCalloutint" /> // Checks that the CV is working correctly
<asp:RequiredFieldValidator ID="RFVStartDt" runat="server" ControlToValidate="txtStartDt"
Display="None" ErrorMessage="Start Date is required" ValidationGroup="ReportDate" /> // ensures a value was added to the textbox
<ajax:ValidatorCalloutExtender ID="VCEreqStartDt" runat="server" TargetControlID="RFVStartDt"
HighlightCssClass="valCalloutint" PopupPosition="BottomRight" /> // Checks that the RFV is working correctly
// End Date
<asp:TextBox ID="txtEndDt" runat="server" CssClass="textboxint" />
<ajax:CalendarExtender ID="calEndDt" runat="server" PopupPosition="BottomRight" TargetControlID="txtEndDt" />
<asp:CompareValidator ID="CVEndDt" runat="server" Type="Date" Operator="GreaterThan"
ErrorMessage="End Date must come after the Start Date" ValidationGroup="ReportDate"
ControlToValidate="txtEndDt" ControlToCompare="txtStartDt" Display="None" />
<ajax:ValidatorCalloutExtender ID="VCEEndDt" runat="server" TargetControlID="CVEndDt"
HighlightCssClass="valCalloutint" />
<asp:RequiredFieldValidator ID="RFVEndDt" runat="server" ControlToValidate="txtEndDt"
Display="None" ErrorMessage="End Date is required" ValidationGroup="ReportDate" />
<ajax:ValidatorCalloutExtender ID="VCEreqEndDt" runat="server" TargetControlID="RFVEndDt"
HighlightCssClass="valCalloutint" PopupPosition="BottomRight" />
Note that the extra ValidatorCalloutExtender tools are not redundant, but actually allows the program to prevent the user from entering an empty value for one of the textboxes.
Hope this helps!!
The calendar control should have a property called SelectedDate. You can compare this property with any other DateTime property. The code snippet below will check if the SelectedDate is greater than today.
if (Calendar.SelectedDate > DateTime.Now())
{
}
I am trying to pull a date from database and putting it on a webpage with the below code:
<asp:Label ID="Label3" runat="server" Text='<%# Eval("TravelDate") %>' /><br /><br />
It pulls the date with no problem, but when it shows up on the page, no matter how it is formatted in the database, it seems to want to always display the date as "6/17/2013 12:00:00am". Is there something I'm missing in the VS portion that I have to use to format the date? I'd prefer "June 17, 2013", but the only option close to that in Access is where it adds the day of the week in front of it. Getting rid of the time is important.
<asp:Label ID="txtDate" Width="65px" runat="server" Font-Size="8.5pt" ForeColor="#000f9f"
Text='<%# Eval("How_date","{0:dd/MMM/yyyy}") %>'></asp:Label>
Try to extract like the field like this:
Expr1:Format([Field Name],"DD/MM/YYYY")
or
If it's a text field then you can use the string function left() or right() to get the date. Expr1:Left([Field Name],10)
Just remove the single quotation mark '' after the property text of the TextBox.
<asp:Label ID="Label3" runat="server" Text=<%# Eval("TravelDate", "{0:MMMM dd, yyyy}") %> /><br /><br />
I want to get the Day of week out of a Date object that im binding to a gridview label like this:
<asp:Label ID="ResourceAvailabilityDayLabel" runat="server" Text='<%# Bind("Date", "{0:d}") %>'></asp:Label>
{0:d} shows only the day in numbers if the date was 11-4-2012 it will post 11. Is there a way to have this done during binding? I cant find the correct DateStringFormat.
Edit
{0:dddd} fixes the problem.
To get day of the week use ddd or dddd format specifier:
<asp:Label ID="ResourceAvailabilityDayLabel" runat="server" Text='<%# Bind("Date", "{0:dddd}") %>'></asp:Label>
In web application, i am using regular expression for date like "dd-mm-yyyy" format for this i get the validation but it is not working when we enter date like "12-02-2012" remaining condition it is working fine, can you help me this is my validation expression.
<asp:RegularExpressionValidator ID ="myg" runat ="server" ControlToValidate ="txt" ErrorMessage ="Check"
ValidationExpression ="^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)-(0[13456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$" >
</asp:RegularExpressionValidator>
I solve the problem,
ValidationExpression ="^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)-(0[123456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"
asp:RegularExpression is not the way to do this.
For validating date using an ASP.NET Validator its ideal to use asp:CompareValidator
Here is a small mock-up
<asp:TextBox ID="txtDatecompleted" runat="server"/>
<asp:CompareValidator ID="dateValidator" runat="server"
ControlToValidate="txtDatecompleted"
ErrorMessage="Please enter a valid date."
Operator="DataTypeCheck"
Type="Date"
ValidationGroup="TestVGroup">
</asp:CompareValidator>
<br />
<asp:Button ID="ClickButton" Text="Click Me" runat="server"
ValidationGroup="TestVGroup"
OnClick="ClickButton_Click" />
This will automatically check for different date formats and leap years
I slove the problem,
ValidationExpression ="^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-((19|[2-9]\d)\d{2}))|
((0[1-9]|[12]\d|30)-(0[123456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])
\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|
((16|[2468][048]|[3579][26])00))))$"
I'm trying to have a textbox function exactly like the third textbox down on this page: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/MaskedEdit/MaskedEdit.aspx. I'm trying to use a CalendarExtender control with a MaskedEditExtender, because I don't want the user to be able to enter anything except a valid date into the box. On my maskededitextender I have a mask of "99/99/9999" but it seems to only work when the date is actually 8 digits (e.g. 12/12/2000) and not when the date is 7 or 6 digits (e.g. 1/1/2000 or 1/14/2000). The mask screws up when the date is less than 8 digits. Here is my code:
<asp:TextBox runat="server" ID="txtDateAvailable" Width="150px" maxlength="50"></asp:TextBox>
<asp:CalendarExtender ID="calDateAvailable" runat="server" TargetControlID="txtDateAvailable" format="d" PopupPosition="Right"></asp:CalendarExtender>
<asp:MaskedEditExtender ID="mskDateAvailable" runat="server" targetcontrolid="txtDateAvailable" Mask="99/99/9999" clearmaskonlostfocus="false" MaskType="None"></asp:MaskedEditExtender>
If I could figure out how to get the date format of the CalendarExtender to MM/DD/YYYY instead of just M/D/YYYY that would fix it.
There is a Format property of Calendar Control. Use that to set to
Format="MM/dd/yyyy"
The syntax for it is as follows: Format="MM/dd/yyyy" and change it around as you wish, but you must ensure that the month is in uppercase otherwise it will return zeros i used -
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1"
PopupButtonID="ImageButton1" Format="dd/MM/yy">