Home All Groups Group Topic Archive Search About

Problems with dynamically created GridView/DetailsView

Author
3 Apr 2006 6:48 PM
Martin Simard
Hello there,

I have some problems when trying to create dynamically (in code behind) a
GridView and DetailsView. Both datasources of the controls are
ObjectDataSource objects.

First problem, when I run my page I got the following error when I click the
"Edit" button in the DetailsView: The DetailsView 'DetailsView' fired event
ModeChanging which wasn't handled    (why?)

I then create the corresponding handler, but the DetailsView refuses to get
in EditMode. I have to add the following code in the handler:
detailsControl.ChangeMode(e.NewMode);  I can now edit my field values, but
other problems follow.

When I click the UpdateButton, it fires the ItemUpdating event handler of my
DetailsView, but the DetailsViewUpdateEventArgs contains nothing. No
NewValues, no OldValues... just empty.

I'm a little bit confused now, since everything works fine when I create the
same page at design time dragging and dropping the
GridView/DetailsView/ObjectDataSource and setting the properties/events.
Both pages contain the same controls, same properties, but different
behaviours.

Maybe I'm missing something in dynamic controls creation. I tried to create
my controls in the Page.OnPreInit and the Page.CreateChildControls methods.
My databings are done in the Page.PreRender method. I tried severals things,
and nothings seems to work. DataBinding problem? ViewState?

Any idea someone?

Author
3 Apr 2006 7:41 PM
Martin Simard
When I say "dynamically created", I mean that it is a composite control. My
control inherits from WebControl and all controls in it (including the
GridView and the DetailsView) are created programmatically.
Author
20 Apr 2006 8:16 PM
Grim
I'm running into the same problem.  Have you resolved this Martin?

Show quoteHide quote
"Martin Simard" wrote:

> Hello there,
>
> I have some problems when trying to create dynamically (in code behind) a
> GridView and DetailsView. Both datasources of the controls are
> ObjectDataSource objects.
>
> First problem, when I run my page I got the following error when I click the
> "Edit" button in the DetailsView: The DetailsView 'DetailsView' fired event
> ModeChanging which wasn't handled    (why?)
>
> I then create the corresponding handler, but the DetailsView refuses to get
> in EditMode. I have to add the following code in the handler:
> detailsControl.ChangeMode(e.NewMode);  I can now edit my field values, but
> other problems follow.
>
> When I click the UpdateButton, it fires the ItemUpdating event handler of my
> DetailsView, but the DetailsViewUpdateEventArgs contains nothing. No
> NewValues, no OldValues... just empty.
>
> I'm a little bit confused now, since everything works fine when I create the
> same page at design time dragging and dropping the
> GridView/DetailsView/ObjectDataSource and setting the properties/events.
> Both pages contain the same controls, same properties, but different
> behaviours.
>
> Maybe I'm missing something in dynamic controls creation. I tried to create
> my controls in the Page.OnPreInit and the Page.CreateChildControls methods.
> My databings are done in the Page.PreRender method. I tried severals things,
> and nothings seems to work. DataBinding problem? ViewState?
>
> Any idea someone?
>
>
>
Author
25 Apr 2006 8:28 PM
Martin Simard
Hi Grim,

I have not resolved this yet. Unfortunately, I put this on hold for a few
weeks.

But I'm still looking for a solution. Our web applications are actually
designed to generate webcontrols on the fly (under VS 2005 .NET 1.1). We
developed a lot of composite controls in a few class libraries which are
reused in different web applications (create dynamically on web forms).

Since then, I looked at the following topic to find new ways of designing
reusable webforms and webcontrols:
http://weblogs.asp.net/scottgu/archive/2005/08/28/423888.aspx

Anyway, we're looking forward to port our actual applications under VS 2005
/ .NET 2.0 and use the new controls and we're still facing the problem
described under.

I hope someone has a solution (or at least a hint) for us.

Martin


Show quoteHide quote
"Grim" <G***@discussions.microsoft.com> wrote in message
news:0D6C3001-8143-442E-9CE2-848DB85ABDD6@microsoft.com...
> I'm running into the same problem.  Have you resolved this Martin?
>
> "Martin Simard" wrote:
>
>> Hello there,
>>
>> I have some problems when trying to create dynamically (in code behind) a
>> GridView and DetailsView. Both datasources of the controls are
>> ObjectDataSource objects.
>>
>> First problem, when I run my page I got the following error when I click
>> the
>> "Edit" button in the DetailsView: The DetailsView 'DetailsView' fired
>> event
>> ModeChanging which wasn't handled    (why?)
>>
>> I then create the corresponding handler, but the DetailsView refuses to
>> get
>> in EditMode. I have to add the following code in the handler:
>> detailsControl.ChangeMode(e.NewMode);  I can now edit my field values,
>> but
>> other problems follow.
>>
>> When I click the UpdateButton, it fires the ItemUpdating event handler of
>> my
>> DetailsView, but the DetailsViewUpdateEventArgs contains nothing. No
>> NewValues, no OldValues... just empty.
>>
>> I'm a little bit confused now, since everything works fine when I create
>> the
>> same page at design time dragging and dropping the
>> GridView/DetailsView/ObjectDataSource and setting the properties/events.
>> Both pages contain the same controls, same properties, but different
>> behaviours.
>>
>> Maybe I'm missing something in dynamic controls creation. I tried to
>> create
>> my controls in the Page.OnPreInit and the Page.CreateChildControls
>> methods.
>> My databings are done in the Page.PreRender method. I tried severals
>> things,
>> and nothings seems to work. DataBinding problem? ViewState?
>>
>> Any idea someone?
>>
>>
>>