C
Code Scorpio
Hi all,
I'm developing a custom control that renders a calendar in a html table. (in
C#)
Let me tell first that is not <asp:calendar> builtin control.
To change the current week (weekly view of the calendar), i've added two <a>
html elements with a code like this :
_render += "<a title='Next Week' id=\"" + this.UniqueID + "\"
href=\"javascript:" + Page.GetPostBackEventReference(this, "Next") +"\">";
_render += "<a title='Previous Week' id=\"" + this.UniqueID + "\"
href=\"javascript:" + Page.GetPostBackEventReference(this, "Prev") +"\">";
I capture the postbacks in the control's Render function : (First question
is this a wrong way to capture the postbacks ?)
protected override void Render(HtmlTextWriter output)
{
if ((Page.IsPostBack) && (Page.Request["__EVENTTARGET"] ==
this.UniqueID))
{
switch (Page.Request["__EVENTARGUMENT"])
{
case "Prev":
this.CalendarDate = this.CalendarDate.AddDays (-7);
break;
case "Next":
this.CalendarDate = this.CalendarDate.AddDays (7);
break;
}
}
else.................
CalendarDate variable is saved in the ViewState with a code like this : (is
this true ?)
[Bindable(true), Category("Calendar")]
public DateTime CalendarDate
{
get
{
return (DateTime)ViewState["CalendarDate"]; // don't forget to check if
it's null or not
}
set
{
ViewState["CalendarDate"] = value;
SetExpressions ();
}
}
When "previous" or "next" week links clicked in the container page, i
capture the postbacks.
And i add or subtract 7 days to the current date saved in the CalendarDate
variable (saved in the ViewState also).
Here is step by step problem with ViewState:
1- CalendarDate set to Today's date by WebForm page load at the first step..
2- I click previous week link..
3- The component successfully subtracts 7 days from the CalendarDate value
and saves it to it self again to obtain ViewState synchronization.
4- Page show the previous week..
5- I click the next week link.. (normally i should see the same week with
step 1)
6- The component successfully adds 7 days BUT to the original value where
the WebForm page set at the step 1.
Even i save the value to the ViewState in the component, ViewState doesn't
change the content..
Please help me, i'm stucked
Thnx
M.Gurel
I'm developing a custom control that renders a calendar in a html table. (in
C#)
Let me tell first that is not <asp:calendar> builtin control.
To change the current week (weekly view of the calendar), i've added two <a>
html elements with a code like this :
_render += "<a title='Next Week' id=\"" + this.UniqueID + "\"
href=\"javascript:" + Page.GetPostBackEventReference(this, "Next") +"\">";
_render += "<a title='Previous Week' id=\"" + this.UniqueID + "\"
href=\"javascript:" + Page.GetPostBackEventReference(this, "Prev") +"\">";
I capture the postbacks in the control's Render function : (First question
is this a wrong way to capture the postbacks ?)
protected override void Render(HtmlTextWriter output)
{
if ((Page.IsPostBack) && (Page.Request["__EVENTTARGET"] ==
this.UniqueID))
{
switch (Page.Request["__EVENTARGUMENT"])
{
case "Prev":
this.CalendarDate = this.CalendarDate.AddDays (-7);
break;
case "Next":
this.CalendarDate = this.CalendarDate.AddDays (7);
break;
}
}
else.................
CalendarDate variable is saved in the ViewState with a code like this : (is
this true ?)
[Bindable(true), Category("Calendar")]
public DateTime CalendarDate
{
get
{
return (DateTime)ViewState["CalendarDate"]; // don't forget to check if
it's null or not
}
set
{
ViewState["CalendarDate"] = value;
SetExpressions ();
}
}
When "previous" or "next" week links clicked in the container page, i
capture the postbacks.
And i add or subtract 7 days to the current date saved in the CalendarDate
variable (saved in the ViewState also).
Here is step by step problem with ViewState:
1- CalendarDate set to Today's date by WebForm page load at the first step..
2- I click previous week link..
3- The component successfully subtracts 7 days from the CalendarDate value
and saves it to it self again to obtain ViewState synchronization.
4- Page show the previous week..
5- I click the next week link.. (normally i should see the same week with
step 1)
6- The component successfully adds 7 days BUT to the original value where
the WebForm page set at the step 1.
Even i save the value to the ViewState in the component, ViewState doesn't
change the content..
Please help me, i'm stucked
Thnx
M.Gurel