views:

441

answers:

1

Greetings,


1) I assume ObjectDataSource automatically binds to data source only on first request, but not on postbacks ( else ObjectDataSource.Selecting event would be fired on postbacks also, but it isn’t):

A) So only way to force ObjectDataSource to also bind on postbacks is by manually calling DataBind()?


2) Assuming DropDownList1 has DataSourceID set to ObjectDataSource1 , then first time page is loaded, ObjectDataSource1 will automatically call DropDownList1.DataBind() ( after Page.PreRender event) and insert retrieved data.


A) But what if we also manually call DropDownList1.DataBind() when page is first loaded:

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack) DropDownList1.DataBind();
}


Will ObjectDataSource1 somehow notice that DropDownList1.DataBind() has already be called and thus won’t automatically call DropDownList1.DataBind() ?


B) Normally ObjectDataSource1.Selecting event is fired after Page.Prerender event.But what if DropDownList1.DataBind() is called inside *Page_Load()*?

Will in that case ObjectDataSource1.Selecting event be fired prior to Page.PreRender?


thanx

+1  A: 

Will in that case ObjectDataSource1.Selecting event be fired prior to Page.PreRender?
Yes it is called prior to Page.PreRender.
Reason: Each data bound control whose DataSourceID property is set calls its DataBind method in prerender event,

check page life cycle http://msdn.microsoft.com/en-us/library/ms178472.aspx

http://dotnetshoutout.com/Data-Binding-Events-for-Data-Bound-Controls-in-ASPNet

Since the load event is called before prerender, and when call databind method then in your situation objectdatasource selected event fired before prerender

Muhammad Akhtar
I assume if the first time page is loaded we manually call DropDownList1.DataBind()(inside Page_Load()), then DropDownList1 won't again call DataBind() in PreRender event?!
SourceC
yes, it is not called
Muhammad Akhtar
thanx for your help
SourceC