detailview loses components after refresh

M

Mike

I have a detailview, with several template columns in it.

It's setup so that a user views info from a datagrid, and if they want
to add another row, they click a button. The button causes a
detailview to open up, in insert mode, they enter the data, hit insert,
and the detailview goes away. Their data now appears in the gridview.
When the user clicks the button to open the detailview, a few databound
labels in 2 of the detailview's template insert columns get set from
the code (see below)

This all works, the first time thru. However, on the second time
through, opening the detailview, I get an unhandled exception when I'm
trying to set the labels to a value. Upon further inspection, I notice
that the detailview has no children controls. This happens whether I
open the detailview, insert data, and save, then re-open the detailview
(failure happens here), or if I just open the detailview, hit the
cancel option, and open the detailview again (failure happens here).

Here is some relevant code, let me know if there's anything else
needed:

protected void cmdAddPermDefault_Click(object sender, EventArgs e)
{
/* This is the button press that makes the detailview visible,
the button invisible, sets two fields within the detailview (Label7 and
Label8 are labels in the insert template) */

dvAppPermissions.Visible = true;
dvAppPermissions.ChangeMode(DetailsViewMode.Insert);
((Label)dvAppPermissions.FindControl("Label7")).Text =
"SYSDEFAULT"; <-- Fails on this line with NullReferenceException (there
are no controls in the dv)
((Label)dvAppPermissions.FindControl("Label8")).Text = appID;
cmdAddPermDefault.Visible = false;
}


protected void dvAppPermissions_ModeChanging(object sender,
DetailsViewModeEventArgs e)
{
/* when the mode of the detail view is changing, I'm checking to
see if it's going back to read only, if so, make it not visible, and
make the add button visible */
if (e.NewMode == DetailsViewMode.ReadOnly)
{
((DetailsView)sender).Visible = false;
cmdAddPermDefault.Visible = true;
}
}



Any pointers as to why the second time through the detailsview there
are no controls?

Thanks,
Mike
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top