Calendar Control custom navigation problems

Discussion in 'ASP .Net Web Controls' started by Giancarlo Persico, Jul 18, 2003.

  1. 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_SelectionChanged);

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

    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);

    }

    }
     
    Giancarlo Persico, Jul 18, 2003
    #1
    1. Advertising

  2. Giancarlo Persico

    Ben Fidge Guest

    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_SelectionChanged);
    >
    > this.ddlYears.SelectedIndexChanged += new
    > System.EventHandler(this.ddlYears_SelectedIndexChanged);
    >
    > 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);
    >
    > }
    >
    > }
    >
    >
    >
    >
     
    Ben Fidge, Jul 18, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Fidge
    Replies:
    0
    Views:
    390
    Ben Fidge
    Jul 18, 2003
  2. msnews.microsoft.com
    Replies:
    2
    Views:
    483
    Steven Cheng[MSFT]
    Apr 22, 2004
  3. Laurahn
    Replies:
    3
    Views:
    910
    Steven Cheng[MSFT]
    Feb 6, 2007
  4. Matt Sokol
    Replies:
    2
    Views:
    390
    Theo Tillotson
    Aug 7, 2003
  5. msnews.microsoft.com

    Calendar Control: Changing the Month Display and Navigation Links

    msnews.microsoft.com, Apr 19, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    184
    Steven Cheng[MSFT]
    Apr 20, 2004
Loading...

Share This Page