Welcome Guest Search | Active Topics | Sign In | Register

question about DatePicker contol in web form... Options
grchen168
Posted: Friday, March 25, 2022 5:19:35 AM
Rank: Member
Groups: Member

Joined: 8/26/2021
Posts: 28
Using DatePicker Control in my webform,

(1) in the dropdown portion, how to switch (that is using mouse only) to different years quickly?
Currently it seems the only way to switch to other year is clicking thru each month till reaching the target year.

(2) in the textbox portion, if I just simply put the datepicker markup in my aspx,
then at runtime, the textbox content is blank (' / / ').
So, I must remember to set its initial value to current date, like this:
if(!IsPostBack)
DatePicker1.SelectedDate=DateTime.Now;
How to configure so that the datepicker control will initially fill its textbox portion with current date?
eo_support
Posted: Friday, March 25, 2022 8:04:58 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,103
Hi,

In order to switch year faster, you would need a custom title template. You can find sample code in the sample project EOWebDemo_CS/Demos/Calendar/Features/Title and Footer Template.aspx. In this sample it uses a year drop down in the title template. You can use anything else it is convenient for you.

You do have to set SelectedDate in your code in order to set the DatePicker's initial value. It does not do that automatically.

Thanks!
grchen168
Posted: Friday, March 25, 2022 10:27:59 AM
Rank: Member
Groups: Member

Joined: 8/26/2021
Posts: 28
Thanks for clear response.

And, for (2), hope you can consider adding the feature in the near future release.
Betina Jessen
Posted: Monday, October 17, 2022 5:53:37 AM
Rank: Newbie
Groups: Member

Joined: 10/17/2022
Posts: 2
A date picker is a client side construct. HTML 5 complaint browsers have this feature and there are JavaScript libraries as well.

C# runs on the server not the client.
Betina Jessen
Posted: Monday, October 17, 2022 5:54:11 AM
Rank: Newbie
Groups: Member

Joined: 10/17/2022
Posts: 2
You could use Calender, TextBox and Button control to achieve the datepicker effect.

First, set the calender to invisible.

Then in the button click event to make the calender visible.

And in the calender's SelectionChanged event to get the selected date.

Here is a simple demo and hope this will be helpfu to you.

.aspx

<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server" Visible="false" OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="GetDate" OnClick="Button1_Click"/>

</form>
code-behind.

protected void Button1_Click(object sender, 2023 calendar printable EventArgs e)
{
Calendar1.Visible = true;
}

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
Calendar1.Visible = false;
}
result:


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.