M
mark.norgate
Hi
I'm writing a timesheet application in ASP.NET (framework 1.1, VS 2003)
that includes a user control to manage project time allocation
(ProjectDetailsControl). This control is a composite control that
includes several DropDownList objects for project code, name and so on,
as well as TextBox objects for time allocation for each day. I had a
problem with this control not rendering when created programmatically,
but I've fixed that. Now I have another problem.
The control is not maintaining its view state, and I'm not sure how
best to implement it. On first entry to the page (and only the first
entry), the project data is loaded from a database and inserted into
the page's ViewState. The page then uses this view state information to
create the appropriate number of ProjectDetailsControl objects.
I thought I would populate the view state in the page and so, as an
experiment, I had something along the lines of:
ViewState["projectDetails_0_ProjectCodeDropDown"] =
projectReader["projectCode"]
This is the ID for the project code drop down generated by the
framework in the HTML. I thought that, since the drop down within my
ProjectDetailsControl is not picking up its state, I'd look in the
Page_Load of my ProjectDetailsControl to see what's actually in the
ViewState object.
Looking at the ViewState in the ProjectDetailsControl, I discovered
that it's actually empty, oddly, even though in the page it has lots of
stuff in it, including all the keys I'd put in myself.
Bit of a ramble...but bottom line is, how do I maintain state in
programmatically create composite user controls? I've had a look at
some articles, such as the Page Controller and Front Controller
patterns on the MSDN site, but they're not particularly illuminating in
terms of the actual nuts and bolts of maintaining state.
Cheers, Mark
I'm writing a timesheet application in ASP.NET (framework 1.1, VS 2003)
that includes a user control to manage project time allocation
(ProjectDetailsControl). This control is a composite control that
includes several DropDownList objects for project code, name and so on,
as well as TextBox objects for time allocation for each day. I had a
problem with this control not rendering when created programmatically,
but I've fixed that. Now I have another problem.
The control is not maintaining its view state, and I'm not sure how
best to implement it. On first entry to the page (and only the first
entry), the project data is loaded from a database and inserted into
the page's ViewState. The page then uses this view state information to
create the appropriate number of ProjectDetailsControl objects.
I thought I would populate the view state in the page and so, as an
experiment, I had something along the lines of:
ViewState["projectDetails_0_ProjectCodeDropDown"] =
projectReader["projectCode"]
This is the ID for the project code drop down generated by the
framework in the HTML. I thought that, since the drop down within my
ProjectDetailsControl is not picking up its state, I'd look in the
Page_Load of my ProjectDetailsControl to see what's actually in the
ViewState object.
Looking at the ViewState in the ProjectDetailsControl, I discovered
that it's actually empty, oddly, even though in the page it has lots of
stuff in it, including all the keys I'd put in myself.
Bit of a ramble...but bottom line is, how do I maintain state in
programmatically create composite user controls? I've had a look at
some articles, such as the Page Controller and Front Controller
patterns on the MSDN site, but they're not particularly illuminating in
terms of the actual nuts and bolts of maintaining state.
Cheers, Mark