本文介绍了这是我们可以强制ObjectDataSource控件的唯一途径...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

结果

1)我假设的 ObjectDataSource控件的自动绑定到数据源只在第一次请求,但不能在回发(其他的 ObjectDataSource.Selecting 的事件将在回传也被解雇,但它不是):

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):

一个),因此只方法来强制的 ObjectDataSource控件的也上回发绑定是手动调用的的DataBind()的?

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

结果

2)假设的 DropDownList1 的已经的的DataSourceID 的设置为 ObjectDataSource1 的,那么第一次加载页面时,的 ObjectDataSource1 的意志自动调用的 DropDownList1.DataBind()的(之后的页。preRender 的事件),并插入检索到的数据。

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)但是,如果我们还手工所谓的 DropDownList1.DataBind()的网页时,第一次加载:

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();
}

结果
威尔的 ObjectDataSource1 的不知何故发现的 DropDownList1.DataBind()的已经被调用,因而不会自动调用的 DropDownList1.DataBind()的?


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

结果

B)一般情况下的 ObjectDataSource1.Selecting 的事件被解雇后的页。prerender 的event.But万一的 DropDownList1.DataBind()的被称为*的Page_Load()里面*?

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

请问在这种情况下的 ObjectDataSource1.Selecting 的事件之前发射的页。preRender 的?

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

结果

感谢名单

推荐答案

将在这种情况下,ObjectDataSource1.Selecting事件之前的页面。preRender解雇?

是的,它先于页面调用。preRender。

原因:每个数据绑定控件的DataSourceID属性设置调用prerender事件的DataBind方法,

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,

检查页面生命周期

由于负载事件之前prerender调用,当调用数据绑定方法,那么在之前prerender解雇你的情况选择的ObjectDataSource事件

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

这篇关于这是我们可以强制ObjectDataSource控件的唯一途径...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 01:55