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

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

问题描述

这个问题似乎微不足道,但我没有用谷歌找到答案.

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

如果我在一个网络表单中有多个独立的控件,例如DropDownLists 和网格,我需要在另一个事件处理程序中使用来自一个事件处理程序的回发信息,因此我需要让它一个接一个地正确触发.

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.

我看到很多间接的方法来做到这一点 - 使用引发自定义事件等,但可能有更好更简单的方法来做到这一点?

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.:如果我需要在另一个控件中使用来自一个控件的回发信息 - 例如RadGrid.NeedDataSource 数据绑定处理程序中的 dropdownlist.SelectedValue - 通常的发送方式是什么?

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.

:Rudnev,我以前使用过 RadGrid,但我不记得 NeedDataSource 事件的确切用途.将下拉列表设置为在更改后自动回发,然后在事件处理程序中,将网格的数据源设置为适当的源,并对其调用 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天全站免登陆