实现 IButtonControl 的自定义 WebControl 的 OnCommand 事件处理程序中的 CommandEventArgs null 值

发布于 2024-09-16 18:50:50 字数 991 浏览 2 评论 0原文

我对这个长标题感到非常抱歉,但我真的不知道如何比这个更自我解释。

我遇到的问题是这样的: 我设计并开发了一个 WebControl,它由一组简单的元素组成,这些元素以最简单的方式组合在一起,定义了一个自定义按钮。我想在我的 Web 应用程序中使用此控件,而不是 Button 和 LinkBut​​ton 控件(原因主要依赖于图形和视觉功能)。 为了让 Webcontrol 表现得像一个按钮,它还实现了 IButtonControl 接口,以便框架处理事件和类似内容所需的所有元素都得到很好的提供。 好吧,这个我称为 BoxButton 的按钮每次使用时都可以正常工作,而不是为了一件事。

对不起,前奏太长了,现在我们可以直接讨论真正的问题了: 在页面中,我有一个 ListView,在列表视图中,我启用了 InsertItemTemplate。 当通过按下模板内的按钮(一个按钮,一个普通的按钮控件)触发 OnItemInsert 时,这个 insertitemtemplate 工作正常。 嗯,我确实想用我的 BoxButton 来代替普通的 BoxButton。当我这样做时,我遇到了问题。 处理函数是这样的:

protected void Insert_BoxButton_Command(object sender, CommandEventArgs e) {
    if (e.CommandName == "Insert") {
        // Do something     
    }
}

通常,e 对象能够向开发人员提供信息,以便找到要插入的所有数据。当我使用普通按钮时这些数据可用,但当使用 BoxButton 时它为空! 好吧,您可以告诉我,当我定义实现 IButtonControl 接口的 BoxButton 时,我必须管理接口中的两个事件(处理按钮压力:单击和命令)并管理提供 CommandEventArgs 的问题。但如何做到这一点呢? 我的问题有解决办法吗?如何管理 eventargs?我感觉这可能是一个非常低的编程问题......也许还有很多事情要做。 预先感谢您的帮助。 安德里

I am very sorry for the long title but I really didn't know how to be more self explaining than this.

The problem I have is this:
I designed and developed a WebControl which consists in a simple set of elements that, combined togheter in the simplest way, defines a custom button. This control is the one I would like to use in my web application instead of Button and LinkButton control (reasons mainly rely on graphic and visual functionalities).
In order to let the webcontrol behave like a button, it also implements the IButtonControl interface so that all elements needed by the framework in order to handle events and similar stuff are well provided.
Well, this button I called BoxButton works fine everytime it is used, instead for one thing.

Sorry for the long prelude, now we can go straight to the real problem:
In a page I have a ListView and in the listview I have the InsertItemTemplate enabled.
Well this insertitemtemplate works fine when the OnItemInsert is fired by pressing a button inside the template (a button, an ordinary button control).
Well, I sure wanted to place my BoxButton in place of the ordinary one. When I do this I have a problem.
The handler function is this:

protected void Insert_BoxButton_Command(object sender, CommandEventArgs e) {
    if (e.CommandName == "Insert") {
        // Do something     
    }
}

Typically, the e object is able to give information to the developer in order to locate all data to be inserted. These data are available when I use a normal button, but when using a BoxButton it is null!
Well, you could tell me that, when I defined my BoxButton implementing the IButtonControl interfaces, I had to manage with both the two events in the interface (dealing woth button pressure: Click and Command) and manage with the problem of providing CommandEventArgs. But how to do this?
Is there a solution to my problem? How can I manage eventargs? I sense that probably this is a very low programming issue... maybe there is much to do.
Thanks in advance for your help.
Andry

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文