简体   繁体   English

SharePoint 2010-WebPart-数据绑定-onPageLoad?

[英]SharePoint 2010 - WebPart - DataBinding - onPageLoad?

A while ago I started working with SharePoint Web Parts (Visual Web Parts). 不久前,我开始使用SharePoint Web部件(Visual Web部件)。 When I was building my first Web Parts I did all my data-binding on PageLoad(). 当我构建第一个Web部件时,我在PageLoad()上完成了所有数据绑定。

Now I've started to build a custom-filter web part which sends filter-options to another web part through a communication interface. 现在,我开始构建一个定制过滤器Web部件,该部件通过通信接口将过滤器选项发送到另一个Web部件。 Basically, it works fine but I noticed that the method for receiving the filter-options (ConnectionConsumer) ran after the PageLoad. 基本上,它工作正常,但我注意到用于接收过滤器选项的方法(ConnectionConsumer)在PageLoad之后运行。 So if I'm using the filter-web part the DataBinding runs twice (on PageLoad and after receiving the FilterData so the filter can take effect). 因此,如果我使用filter-web部件,则DataBinding将运行两次(在PageLoad上并在收到FilterData之后,以便过滤器可以生效)。

So I guess that there is a better place to bind the data to my web part apart from PageLoad. 因此,我认为除了PageLoad之外,还有更好的方法将数据绑定到我的Web部件。

And now my question: Where should I bind the data? 现在我的问题是:我应该在哪里绑定数据?

The rule of thumb is to bind data just before rendering. 经验法则是在渲染之前绑定数据。 Override PreRender event instead and do the binding logic there. 改写PreRender事件,并在那里执行绑定逻辑。

I had a similar issue where my page load was being fired twice. 我遇到了类似的问题,页面加载被触发了两次。 I just commented out the "Handles Me.Load" and it worked fine. 我刚刚注释掉了“ Handles Me.Load”,它运行良好。 If you set AutoEventWireup to true, make sure that you do not also manually attach page event handlers to events. 如果将AutoEventWireup设置为true,请确保不要同时将页面事件处理程序手动附加到事件。 If you do, handlers might be called more than one time. 如果这样做,处理程序可能会被多次调用。 Check this link on MSDN for more details: http://msdn.microsoft.com/en-us/library/system.web.configuration.pagessection.autoeventwireup(v=vs.110).aspx 检查MSDN上的此链接以了解更多详细信息: http : //msdn.microsoft.com/zh-cn/library/system.web.configuration.pagessection.autoeventwireup(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM