你如何管理asp.net触发事件的顺序? [英] How do you manage the order of firing events in asp.net?

查看:169
本文介绍了你如何管理asp.net触发事件的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎是微不足道的,但我没有找到与谷歌的答案。

The question seems to be trivial, but i didn't found an answer with google.

如果我有多个独立控制在基于web的表单,例如DropDownLists和网格,我需要在另一个事件处理程序使用从一个事件处理回发信息,因此我需要,使其正常火一把aonther后。

If I have multiple independent controls in a web-form, e.g. DropDownLists and grid, and I need to use postback information from one eventhandler in another eventhandler, therefore i need to make it fire properly one after aonther.

我看到了很多间接的方式来做到这一点 - 与raise自定义事件等,但有可能是更好,更简单的方法呢?

I see a lot of indirect ways to do it - with raise custom event etc., but probably there is better and simpler way to do it?

UPD:如果我需要在另一个使用回传信息从一个控件 - 例如dropdownlist.SelectedValue在RadGrid.NeedDataSource数据绑定处理程序 - 什么是发送它通常的方式?

UPD.: if I need to use postback info from one control in another - e.g. dropdownlist.SelectedValue in RadGrid.NeedDataSource databinding handler - what is the usual way to send it?

推荐答案

不幸的是,你不应该依赖一个点火顺序上构建的事件处理程序。这不是一个推荐的做法。从 ASP.NET Web服务器控件事件模型

Unfortunately, you should not be constructing event handlers that rely on a firing order. This is not a recommended practice. From ASP.NET Web Server Control Event Model:

您不应该创建应用程序
  它依赖于更改事件逻辑
  以特定的顺序被升高
  除非你有详细的了解
  网页事件处理。有关详细信息,
  看到 ASP.NET页生命周期概述

You should not create application logic that relies on the change events being raised in a specific order unless you have detailed knowledge of page event processing. For details, see ASP.NET Page Life Cycle Overview.

有可能是你的设计有一个缺点,如果你是靠这个。如果您张贴一些更多的细节,我们可以看到,如果我们可以帮助你解决它。

There is probably a flaw in your design if you are relying on this. If you post some more details, we can see if we can help you get around it.

编辑::鲁德涅夫,我用radgrid控件之前,但我不记得NeedDataSource事件的确切目的。那岂不是足够设置你的DropDownList自动回发,一旦它被更改,然后在事件处理程序,设置网格,以适当的源的数据源,并在其上​​调用DataBind()?

: Rudnev, I've used RadGrid before but I can't remember the exact purpose of the NeedDataSource event. Wouldn't it be sufficient to set your dropdownlist to automatically post back once it's been changed, and then in the event handler, set the DataSource of your Grid to the appropriate source, and call DataBind() on it?

这篇关于你如何管理asp.net触发事件的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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