这是我们强制ObjectDataSource的唯一方法吗? [英] Is this the only way we can force ObjectDataSource to…?

查看:212
本文介绍了这是我们强制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):

A)所以只有通过手动调用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()(在 Page.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)通常在 Page.Prerender 事件之后触发 EventDataSource1.Selecting 事件但是如果在 Page_Load()中调用了DropDownList1.DataBind()?

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

在这种情况下, em> ObjectDataSource1.Selecting 事件在 Page.PreRender 之前被触发?

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


thanx

推荐答案

在这种情况下,是否会在Page.PreRender之前触发ObjectDataSource1.Selecting事件?

是是在Page.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,

检查页面生命周期
http://msdn.microsoft.com/en -us / library / ms178472.aspx

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

由于加载事件在prerender之前被调用,并且当调用databind方法时,在你的情况下objectDatasource选择事件在prerender之前触发

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

这篇关于这是我们强制ObjectDataSource的唯一方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆