I
Iain
Hi
I have page (testCal.aspx) that contains a usercontrol (custCalendar.ascx) -
see below signature for code. The UC contains a linkbutton which which when
clicked, posts back and displays a calendar. When a value in the calendar is
selected it posts back and then updates a public property (CurrentDate) on
the UC. Note that 2 postbacks occur.
I have been attempting to access the public property on the UC, from the
page (testCal) shown below. The problem is that the label on the page, set
to CurrentDate on Page_Load, only changes when the LinkButton is clicked to
change the date for a second time. ie. On a further postback.
Thanks in advance.
-Iain
public class testCal : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbl;
protected custCalendar myCal;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("<br>Source = " + Request.Form["__eventtarget"] +"<br>");
lbl.Text = CurrentDate;
}
}
public abstract class custCalendar : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox txtDate;
protected System.Web.UI.WebControls.LinkButton lnkShowCalendar;
protected System.Web.UI.WebControls.Calendar myCalendar;
public String BackColor ="white";
public String ForeColor ="black";
public string CurrentDate {
get { return txtDate.Text; }
set { txtDate.Text = value; }
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
txtDate.Text = CurrentDate;
}
public void CheckDay(Object Source, DayRenderEventArgs E) {
//snipped
}
public void HandleCalendar(Object sender, EventArgs e) {
myCalendar.Visible = !myCalendar.Visible;
if (myCalendar.Visible)
lnkShowCalendar.Text = " 5 ";
else
lnkShowCalendar.Text = " 6 ";
}
public void SelectionChanged(Object sender, EventArgs e) {
txtDate.Text = myCalendar.SelectedDate.ToShortDateString();
CurrentDate = myCalendar.SelectedDate.ToShortDateString();
myCalendar.Visible = !myCalendar.Visible;
lnkShowCalendar.Text = " 6 ";
}
}
I have page (testCal.aspx) that contains a usercontrol (custCalendar.ascx) -
see below signature for code. The UC contains a linkbutton which which when
clicked, posts back and displays a calendar. When a value in the calendar is
selected it posts back and then updates a public property (CurrentDate) on
the UC. Note that 2 postbacks occur.
I have been attempting to access the public property on the UC, from the
page (testCal) shown below. The problem is that the label on the page, set
to CurrentDate on Page_Load, only changes when the LinkButton is clicked to
change the date for a second time. ie. On a further postback.
Thanks in advance.
-Iain
public class testCal : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbl;
protected custCalendar myCal;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("<br>Source = " + Request.Form["__eventtarget"] +"<br>");
lbl.Text = CurrentDate;
}
}
public abstract class custCalendar : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox txtDate;
protected System.Web.UI.WebControls.LinkButton lnkShowCalendar;
protected System.Web.UI.WebControls.Calendar myCalendar;
public String BackColor ="white";
public String ForeColor ="black";
public string CurrentDate {
get { return txtDate.Text; }
set { txtDate.Text = value; }
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
txtDate.Text = CurrentDate;
}
public void CheckDay(Object Source, DayRenderEventArgs E) {
//snipped
}
public void HandleCalendar(Object sender, EventArgs e) {
myCalendar.Visible = !myCalendar.Visible;
if (myCalendar.Visible)
lnkShowCalendar.Text = " 5 ";
else
lnkShowCalendar.Text = " 6 ";
}
public void SelectionChanged(Object sender, EventArgs e) {
txtDate.Text = myCalendar.SelectedDate.ToShortDateString();
CurrentDate = myCalendar.SelectedDate.ToShortDateString();
myCalendar.Visible = !myCalendar.Visible;
lnkShowCalendar.Text = " 6 ";
}
}