Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Calendar Control custom navigation problems

Reply
Thread Tools

Calendar Control custom navigation problems

 
 
Giancarlo Persico
Guest
Posts: n/a
 
      07-18-2003
I have a simple calendar control with a dropdownlist underneath which allows
the user to select the year they wish the calendar to display. The
dropdownlist has AutoPostBack set to true and works fine EXCEPT for after
you navigate the calendar using next/previous - the dropdownlist then no
longer updates the calendar?

In the pageload event I have tried reassigning the dropdownlist
onselectionchange event handler to no avail.

Any help/suggestions would be greatly appreciated. Please take a look at my
code below.


Thanks

Gian

public class CalendarSelector : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Calendar calSelector;

protected System.Web.UI.WebControls.DropDownList ddlYears;

protected System.Web.UI.WebControls.Literal Literal1;

protected DateTime dDateToday = DateTime.Now;

protected int iYear = DateTime.Now.Year;


private void Page_Load(object sender, System.EventArgs e)

{

if(!IsPostBack) {

for(int i = 1900; i <= DateTime.Now.Year; i++) {

ddlYears.Items.Add(new ListItem(i.ToString()));

}

Utils.SetDropDownListUKey(ddlYears, Convert.ToInt32(DateTime.Now.Year));

}

}


private void calSelector_SelectionChanged(object sender, System.EventArgs e)
{

string strjscript = "<script language='javascript'>";

strjscript += "window.opener." +
HttpContext.Current.Request.QueryString["formname"];

strjscript += ".value = '" + calSelector.SelectedDate.ToString("d") +
"';window.close();";

strjscript += "</script" + ">"; //Don't ask, tool bug.

Literal1.Text = strjscript;

}


#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.calSelector.SelectionChanged += new
System.EventHandler(this.calSelector_SelectionChan ged);

this.ddlYears.SelectedIndexChanged += new
System.EventHandler(this.ddlYears_SelectedIndexCha nged);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void ddlYears_SelectedIndexChanged(object sender, System.EventArgs
e) {

int iYearDiff = iYear - Convert.ToInt32(ddlYears.SelectedItem.Value);

calSelector.TodaysDate = dDateToday.AddYears(-iYearDiff);

}

}




 
Reply With Quote
 
 
 
 
Ben Fidge
Guest
Posts: n/a
 
      07-18-2003
Gian

Try using the TodaysDate property of the calendar instead of VisibleDate in
the SelectedIndexChanged event handler

Ben

"Giancarlo Persico" <> wrote in message
news:...
> I have a simple calendar control with a dropdownlist underneath which

allows
> the user to select the year they wish the calendar to display. The
> dropdownlist has AutoPostBack set to true and works fine EXCEPT for after
> you navigate the calendar using next/previous - the dropdownlist then no
> longer updates the calendar?
>
> In the pageload event I have tried reassigning the dropdownlist
> onselectionchange event handler to no avail.
>
> Any help/suggestions would be greatly appreciated. Please take a look at

my
> code below.
>
>
> Thanks
>
> Gian
>
> public class CalendarSelector : System.Web.UI.Page
>
> {
>
> protected System.Web.UI.WebControls.Calendar calSelector;
>
> protected System.Web.UI.WebControls.DropDownList ddlYears;
>
> protected System.Web.UI.WebControls.Literal Literal1;
>
> protected DateTime dDateToday = DateTime.Now;
>
> protected int iYear = DateTime.Now.Year;
>
>
> private void Page_Load(object sender, System.EventArgs e)
>
> {
>
> if(!IsPostBack) {
>
> for(int i = 1900; i <= DateTime.Now.Year; i++) {
>
> ddlYears.Items.Add(new ListItem(i.ToString()));
>
> }
>
> Utils.SetDropDownListUKey(ddlYears, Convert.ToInt32(DateTime.Now.Year));
>
> }
>
> }
>
>
> private void calSelector_SelectionChanged(object sender, System.EventArgs

e)
> {
>
> string strjscript = "<script language='javascript'>";
>
> strjscript += "window.opener." +
> HttpContext.Current.Request.QueryString["formname"];
>
> strjscript += ".value = '" + calSelector.SelectedDate.ToString("d") +
> "';window.close();";
>
> strjscript += "</script" + ">"; //Don't ask, tool bug.
>
> Literal1.Text = strjscript;
>
> }
>
>
> #region Web Form Designer generated code
>
> override protected void OnInit(EventArgs e)
>
> {
>
> //
>
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
>
> //
>
> InitializeComponent();
>
> base.OnInit(e);
>
> }
>
>
> /// <summary>
>
> /// Required method for Designer support - do not modify
>
> /// the contents of this method with the code editor.
>
> /// </summary>
>
> private void InitializeComponent()
>
> {
>
> this.calSelector.SelectionChanged += new
> System.EventHandler(this.calSelector_SelectionChan ged);
>
> this.ddlYears.SelectedIndexChanged += new
> System.EventHandler(this.ddlYears_SelectedIndexCha nged);
>
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
>
> #endregion
>
> private void ddlYears_SelectedIndexChanged(object sender, System.EventArgs
> e) {
>
> int iYearDiff = iYear - Convert.ToInt32(ddlYears.SelectedItem.Value);
>
> calSelector.TodaysDate = dDateToday.AddYears(-iYearDiff);
>
> }
>
> }
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable the navigation buttons for IE navigation toolbar Laurahn ASP .Net 3 02-06-2007 04:17 AM
Calendar Control: Changing the Month Display and Navigation Links msnews.microsoft.com ASP .Net 2 04-22-2004 09:55 AM
Calendar Control: Changing the Month Display and Navigation Links msnews.microsoft.com ASP .Net Web Controls 1 04-20-2004 02:20 AM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM
Re: Calendar Control custom navigation problems Ben Fidge ASP .Net 0 07-18-2003 01:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57