Calendar Control custom navigation problems

G

Giancarlo Persico

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

}

}
 
B

Ben Fidge

Gian

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

Ben
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top