Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar Control

Status
Not open for further replies.

flanakin

Programmer
Mar 21, 2000
158
US
For some reason, my calendar control is giving me an old date. In my Page_Load method, I am outputting the SelectedDate, but it is always one old. For instance...

Date Clicked Output Value
Load 01/01/0001
10/23/2002 01/01/0001
10/25/2002 10/23/2002
10/10/2002 10/25/2002

Has anyone ever had this problem? I don't understand! Thanks in advance! ________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
I just tested your situation in an app i am working on, and I get the correct date for the first date clicked.

Can you supply a little more code?
 
Sure thing.

HTML...

<asp:calendar
id=&quot;calEvents&quot;
width=&quot;80%&quot;
runat=&quot;server&quot;
nextmonthtext=&quot;<sup>Next</sup>&quot;
prevmonthtext=&quot;<sup>Prev</sup>&quot;
showgridlines=&quot;True&quot;
style=&quot;border:solid 1px #003399;&quot;>
<todaydaystyle horizontalalign=&quot;Right&quot; verticalalign=&quot;Top&quot; />
<daystyle horizontalalign=&quot;Right&quot; forecolor=&quot;#3366FF&quot; verticalalign=&quot;Top&quot; />
<nextprevstyle verticalalign=&quot;Top&quot; />
<dayheaderstyle horizontalalign=&quot;Center&quot; height=&quot;16px&quot; verticalalign=&quot;Middle&quot; />
<selecteddaystyle font-bold=&quot;True&quot; horizontalalign=&quot;Right&quot; forecolor=&quot;Blue&quot; verticalalign=&quot;Top&quot; />
<titlestyle backcolor=&quot;#eeeeee&quot; height=&quot;18px&quot; verticalalign=&quot;Middle&quot; />
<weekenddaystyle horizontalalign=&quot;Right&quot; forecolor=&quot;#666666&quot; cssclass=&quot;CalendarWeekendDay&quot; verticalalign=&quot;Top&quot; />
<othermonthdaystyle horizontalalign=&quot;Right&quot; forecolor=&quot;#AAAAAA&quot; verticalalign=&quot;Top&quot; />
</asp:calendar>


Code Behind...

protected System.Web.UI.WebControls.Calendar calEvents;
protected System.Web.UI.WebControls.Literal litEvents;

private void Page_Load(object sender, System.EventArgs e)
{
// declare vars
string strDate; // date

// if new page load, set default date
if (!IsPostBack) calEvents.SelectedDate = DateTime.Today;

// initialize vars
strDateArg = calEvents.SelectedDate.ToShortDateString();

litEvents.Text = calEvents.SelectedDate.ToShortDateString();
}


Let me know if this helps...I trimmed out some other code that doesn't affect this (it was within a try/catch block). Thanks for taking a look at it. ________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
I tried your scenario and I get the same bug that you have. It seems as if the calendar isn't being updated before the page load event happens. To fix this simple put your displaying code in the prerender event. This is the last event to happen before the html is sent off to the browser, so the calendar now has the updated value in it.

The following code worked for me.
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString
End Sub


HTH That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
I ended up just putting it in an OnSelectionChanged method, and just explicitly calling it when the page is initially loaded (and the value is set programmatically). ________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
whatever works That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top