onItemDataBound event not firing on first go thru since moving to .net 2.0

T

TS

I have this custom data list control and i override the onItemDatabound
event. After upgrading to vs 2005, this event is not always getting called,
though it does at other times. No changes were made when upgrading to 2.0

is there any reason for this because of .net 2.0?

thanks
 
T

TS

it is a control that inherits from DataList. The databinding does occur
after the page has posted back in some other parts of code - which correctly
calls the onDataBound event.

Also, this code worked correctly in 1.x but now fails.

thanks!
 
T

TS

Also Why is it that this custom dataList of mine calls DataBind()
automatically (i know this because when my itemDataBound event runs, it runs
twice when i manually call DataBind())?

I also have a regular dataGrid on the page, but if i dont' set DAtaBind()
for it, it won't bind itself. Since DataList and DataGrid both inherit from
BAseDataList, i would expect both to either call databind() automatically or
not at all.

Whats the deal here?

thanks
 
T

TS

actually i think that it doesn't call DataBind() automatically, i found a
spot that was calling it anyways.
 
E

Eric

If a control has a DataSource, DataBind will automatically be called.
I'm not sure if this is the case for you or not.

Are you using .NET 1.1 or 2.0? It sounds like you're still using 1.1.
2.0 doesn't have the DataGrid control (it has been replaced with the
GridView) and the onItemDatabound event is generally called DataBound.
 
W

Walter Wang [MSFT]

Although it's recommended to use GridView in 2.0, DataGrid is still
supported in 2.0. It's actually improved to support a new way of
databinding that using DataSource control.

When you're using declarative way to set the DataSourceID property of a
data-bound control, you don't have to call DataBind() manually; but you
have to call DataBind() if you're setting DataSource property in code.

TS, would you please post some code of your DataList inherited control?
Thanks.


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

TS

to re-iterate, after the first time the databind event occurs during a
postback, it fails. The second time and every time after that, you postback
and call it and it works.
 
T

TS

OK the way the page is set up, initial page load occurs then a postback
occurs which calls the databind. If I put a call to databind during initial
page load, the itemDataBound event is called correctly. For some reason the
intial call to databind when called during the 1st postback is causing
problems.

One other thing to keep in mind is that for some reason the page_load &
page_pre_render are running twice (probably all the page's events). The page
load runs twice, then pre-render runs twice in that exact order, so it
DOESNT' do a load-->pre-render-->Load-->pre-render. IT DOES
load-->load-->pre-render-->pre-render. I am attaching the stack track to
show you the difference comparing the 1st load to the 2nd load which both
occur on a single request for the page.

I have verified that this does not happen in VS 2003 with the same page and
i can find no other pages in vs 2005 that have their load event run twice.
This page is identical except for vs 2005 specific revisions which don't
change anything. This page does have a base class, but its load event only
runs ONCE!

When I put a call to databind during initial page load, the itemDataBound
event is called correctly for both page posts.

If you think double events firing is unrelated to our issue then no
investigation is required.

Thanks!
 
W

Walter Wang [MSFT]

Hi TS,

Thanks for your detailed description. Based on my understanding, the
initial issue you mentioned about your control's OnItemDataBound event is
actually caused by the whole page's events will be fired twice?

Since I have difficulty to run your attached code (it's not complete and
doesn't have a webform to test the issue), I'm afraid I cannot tell what
went wrong exactly. Is it possible for you to create a small but complete
web site project which can reproduce the issue you described? Thank you
very much for your effort.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

TS

i'll try to get to that in a day or 2.

What could be a reason for each of the page's events firing twice each in a
row (remember that it goes Load->Load->Render->Render and NOT
Load->render->Load->Render)

thanks
 
W

Walter Wang [MSFT]

One possible cause is registering the same event handler twice.

Anyway, let's see if it can be reproduced easily.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi,

It seems the attached file is corrupt. Would you please send it again to me
via email? Thanks.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

TS

We took this offline and it is now fixed. The below answer will explain why
the onItemDataBound event was not getting called consistently - deals with
new data binding model of .net 2.x:

I had to add a line of code to also set base.DataSource when I was
overriding the implementation because BaseDataList.DataSource's Setter
changes an internal flag: "this.RequiresDataBinding = true"; this is a
important flag to let the engine know that this control will do the
databinding. I think this is one important change from 1.1 to 2.0 since it
needs to add support for data source controls (declarative data binding via
DataSourceID).
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top