Ben Clarke Ben Clarke - 1 year ago 26
ASP.NET (C#) Question

Keep ASP.NET Calender Open On Month Click

I know people have asked this over the Internet before but i have not used ant Javascript and have done it very basic.

Basically when they click an (ImageButton)icon next to a Textbox it will trigger an OnClick event in the C# which will make the Calender visable. Then when they selected anything on that calender it will trigger SelectionChanged on c# agian and then will set the date they clicked on in a Textbox.


<input id="txt_DateOfInterview" type="Date" class="aclass" runat="server" />

<asp:ImageButton runat="server" imageurl="~/Images/Calender.png" id="calendericonDOI" CssClass="calendericonDOI ClanderDOI" OnClick="calendericonDOI_Click" ></asp:ImageButton>

<asp:calendar runat="server" ID="ClanderDOI" CssClass="ClanderDOI" OnSelectionChanged="ClanderDOI_SelectionChanged" BorderColor="#6a3d98">
<TitleStyle BackColor="Orange"/>


protected void calendericonDOI_Click(object sender, ImageClickEventArgs e)
ClanderDOI.Visible = true;

protected void ClanderDOI_SelectionChanged(object sender, EventArgs e)
txt_DateOfInterview.Value = ClanderDOI.SelectedDate.Date.ToString("d");
ClanderDOI.Visible = false;

Question: How can I make the calender stay visable when they click to see next month only.

Answer Source

Your sample code works as you expect. When you change selected month it does not trigger 'SelectionChange' event.

There is separate event for month change (VisibleMonthChanged) where you can hide calendar, but to achieve what you want just make sure that you do not hide calendar somewhere else in your code:

protected void ClanderDOI_VisibleMonthChanged(object sender, MonthChangedEventArgs e) { ClanderDOI.Visible = true; }

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download