Groups | Blog | Home
all groups > asp.net webcontrols > july 2003 >

asp.net webcontrols : Calendar Control custom navigation problems


Giancarlo Persico
7/18/2003 12:47:48 PM
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
7/18/2003 2:00:41 PM
Gian

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

Ben

[quoted text, click to view]

AddThis Social Bookmark Button