R
Roger
I have created a UserControl, and I am dynamically adding
it to each row of a datagrid with a sub called by the
datagrid's 'OnItemDataBound'. That part works.
'creates the instance of the control
Dim ctl As MyCtl = CType(LoadControl("MyCtl.ascx"), MyCtl)
'adds it to the datagrid inside a template column
e.Item.Cells(1).Controls.Add(ctl )
The problem is that the user control gone postback is
performed. For instance, the user control has a button,
and code handling the click event of that
button. The code for the click never gets executed. The
control is lost on postback.
That can be fixed by performing the binding on the
datagrid again, which triggers the dynamic creation of
the control again, and the click even code is executed.
The problem with that solution is that there is a
database round trip, and the entire page is rendered
again all to perform a simple click event.
Any ideas? Is there different way to create the user
controls, so they persist? How about a better way of
doing what I need? I would just use item templates, but I
need datagrids imbeded within rows of other datagrids. If
you dynamically create a datagrid and add it to a cell of
another grid, you dont have the ability to modify item
templates of the dynamically created grid. (or am I wrong
about that too).
Any help appreciated,
Roger
it to each row of a datagrid with a sub called by the
datagrid's 'OnItemDataBound'. That part works.
'creates the instance of the control
Dim ctl As MyCtl = CType(LoadControl("MyCtl.ascx"), MyCtl)
'adds it to the datagrid inside a template column
e.Item.Cells(1).Controls.Add(ctl )
The problem is that the user control gone postback is
performed. For instance, the user control has a button,
and code handling the click event of that
button. The code for the click never gets executed. The
control is lost on postback.
That can be fixed by performing the binding on the
datagrid again, which triggers the dynamic creation of
the control again, and the click even code is executed.
The problem with that solution is that there is a
database round trip, and the entire page is rendered
again all to perform a simple click event.
Any ideas? Is there different way to create the user
controls, so they persist? How about a better way of
doing what I need? I would just use item templates, but I
need datagrids imbeded within rows of other datagrids. If
you dynamically create a datagrid and add it to a cell of
another grid, you dont have the ability to modify item
templates of the dynamically created grid. (or am I wrong
about that too).
Any help appreciated,
Roger