I need to make a textbox that will select date range. It needs to display two calendars (Start Date and End Date) when it gets clicked. I am using Ajax control toolkit but it shows only one calendar and when I add two calendars with same TargetControlID, it still shows one calender.
<asp:TextBox ID="startDate" Text="Start Date" ReadOnly="False" EnableViewState="True" CssClass="calendar" runat="server">
</asp:TextBox>
cc1:CalendarExtender EnabledOnClient="True" DefaultView="Days" PopupButtonID="calenderopener"
ID="startDate_CalendarExtender" StartDate="Jan 15, 2014" CssClass="ajax__calendar ajax__calendar_container" EnableViewState="True"
runat="server" BehaviorID="calendar1" Enabled="True" TargetControlID="startDate" Format="MM/dd/yyyy">
</cc1:CalendarExtender>
I want to show two calendars when this textbox gets clicked.
Try this. This allows you to select multiple dates to single control(Textbox). If you want to use date range (only two days are selectable) then you shoud have to validate it in your code behind.
http://www.obout.com/calendar/tutorial_select_multipledates.aspx
Related
im trying to make textbox which will handle different dates. For that im using ajaxtoolkit so that when a user clicks on the textbox a popup calender will appear beneath the textbox. I have managed to do that but the problem is that it only shows arond 18 days of the month and i would like to show all of the days in a month. I'm attaching a picture so you can see how it looks.
Here is the code:
<td><asp:TextBox ID="txtValidFrom" runat="server"TextMode="DateTime" >
</asp:TextBox></td>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtValidFrom" FirstDayOfWeek="Monday" Format="dd/MM/yyyy" >
</ajaxToolkit:CalendarExtender>
It seems your CSS rules conflict with Calendar CSS rules.
You can strip all custom CSS to see that Calendar renders correctly and determine what code actually affects Calendar's CSS.
I'm using a RegularExpressionValidator in ASP.NET. I have these validators for my asp:Textbox control:
<asp:RangeValidator
ID="rvDate"
runat="server"
ControlToValidate="txtCrimeDate"
Type="Date"
ErrorMessage="Must be within latest three months"
Display="Dynamic"
OnInit="RangeValidator_Init">
</asp:RangeValidator>
<asp:RegularExpressionValidator
ID="revDate"
runat="server"
ControlToValidate="txtCrimeDate"
Display="Dynamic"
ErrorMessage="Must be in format YYYY-MM-DD"
ValidationExpression="[0-9]{4}-[0-9]{2}-[0-9]{2}">
</asp:RegularExpressionValidator>
I have set the min and max value of the RangeValidator in the code-behind and it works as intended. But! If I enter something with 2 numbers for the year, like 15-11-28 everything passes, even the other validators for the other controls. Any ideas?
Check the date format (US or otherwise) and 0-9 for the day and month are incorrect eg:
2013-99-99
Look into using the CompareValidator control, this is mainly used for string matching, but can be made to check between two date ranges.
I have an asp.net page with a an html5 TextBox control set as the "date" type. The control on my page looks like this:
<asp:TextBox ID="TextBoxMyDate" runat="server" type="date"/>
It works great in the page and I can click on it and set the date. I can also read the date through TextBoxMyDate.Text. However, I cannot figure out how to programaticaly set the date. I have tried various formats of:
TextBoxMyDate.Text = DateTime.UtcNow.ToString("MM/dd/yyyy")
TextBoxMyDate.Text = DateTime.UtcNow.ToString("MM/dd/yyyy")
My guess is that its much more complicated than simply setting the text value but I don't know where to go from here. Any suggestions?
This is actually the correct way to set the date but the format was wrong!
TextBoxMyDate.Text = DateTime.UtcNow.ToString("yyyy-MM-dd");
I was confusing how the browser displays the date and the html5 standards for this control!
Yes, it is quite possible. Here is an example of a date selection filter with ajaxcontrotoolkit and the textbox field.
Overview:calendar ajaxControlToolkit Overview
Tutorial:Tutorial ajaxControlTollkit Date textbox
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
<asp:CalendarExtender
ID="CalendarExtender1"
TargetControlID="txtStartDate"
runat="server" />
I have a textbox in the webpage.
//.aspx
<td class="style2">Start of Date:<asp:TextBox ID="TextBox1" runat="server"
Height="22px"
ontextchanged="TextBox1_TextChanged" Width="157px"></asp:TextBox>
</td>
//aspx.cs
protected void cntCalendar_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = cntCalendar.TodaysDate.ToShortDateString();
}
Now I'm able to take the value in the textbox from calendar,but my problem is I'm not able to get the calendar to show onclick in the textbox and hide after date selected.
Can anybody help me with this please.
Use the CalendarExtender class from the ASP.NET AJAX ToolKit.
Download and usage
You shouldn't do the post backs for the selecting date.
Sounds like you want to use something like the AJAX calendar extender. This control will negate the need of the asp:Calendar control.
See below for an example.
<asp:TextBox ID="txtStartDate" runat="server" CausesValidation="true" >
</asp:TextBox>
<ajax:CalendarExtender ID="ce1" runat="server" Format="dd-MM-yyyy" TargetControlID="txtStartDate" PopupPosition="Right" >
</ajax:CalendarExtender>
The calendar will popup on click and when a date is selected, the textbox will be populated with the date selected in the format specified in the Format attribute
VMAtm is right on with the CalendarExtender.
However, if you have your own custom calendar you're using and you just need to manually pop that up via client onclick of the textbox, do this in Page_Load or PreRender:
TextBox1.Attributes["onclick"] = "showMyCalendar();";
or
TextBox1.Attributes[HtmlTextWriterAttribute.Onclick] = "showMyCalendar();";
I have got a page that has 2 "forms" (What I mean by a form here is a Panel consisting of: textboxes, validators and a button).
(I got 2 here because one of them is actually on the MasterPage, shown all the time)
The problem is when you try to submit to one of the form, it will validate the other form, which of course is blank and invalid.
How do you solve this problem?
Thank you.
Your problem can be solved with asp.net ValidationGroups.
http://weblogs.asp.net/scottgu/archive/2004/10/24/246945.aspx
Basically, you group the controls to be validated using a uniquely named validation group. Like so:
<asp:Textbox ID="txt" runat="server" />
<asp:RequiredFieldValidator id="rfv" runat="server" ControlToValidate="txt" ValidationGroup="masterGroup">* Required!</asp:RequiredFieldValidator>
<br />
<asp:Button id="btnSubmitMaster" runat="server" Text="Submit!" ValidationGroup="masterGroup" />
If you group your inputs like this, then assign the validation group to the control that submits the form, the inputs in the other validation groups won't be validated.