为什么不为“Web 用户控件”自动生成的事件在后面的代码中为 aspx 页面创建 EventHandler 参数

问题描述

我正在使用

  • Visual Studio 2012
  • .NET 框架 4.5
  • Visual Basic 2012 (VB 11.0)

我有 web 用户控件 ascx 页面:MyControl.ascx

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MyControl.ascx.vb" Inherits="MyControl" %>
<asp:Button runat="server" ID="MyButton" OnClick="MyButton_Click" />

我有一个 Web 用户控件代码:MyControl.ascx.vb

Public Class MyControl
    Inherits System.Web.UI.UserControl

    Public Event MyClick As EventHandler

    Protected Sub MyButton_Click(sender as Object,e as EventArgs) Handles MyButton.Click
        RaiseEvent MyClick(sender,e)  
    End Sub
End Class

然后我有一个使用用户控件的页面:MyPage.aspx

<%@ Register Src="UserControls/MyControl.ascx" TagPrefix="ucMyControl" TagName="MyControl" %>
<div>
    <ucMyControl:MyControl runat="server" ID="UcMyControl" OnMyClick="UcMyControl_MyClick" />
</div>

当我从智能中选择<Create New Event>时,如下图所示

enter image description here

生成UcMyControl_MyClick 不包含 sender as Object,e as EventArgs 参数。见下文:

Protected Sub UcMyControl_MyClick()
End Sub

期望是像这样创建事件处理程序参数:

Protected Sub UcMyControl_MyClick(sender As Object,e As EventArgs)
End Sub

我是 ASP.NET 和 Web 用户控件的新手。我已经广泛搜索了这个问题,但无济于事。我在 MyControl.ascx.vb 文件中做了以下操作

1.

Public Delegate Sub MyControlEventHandler(sender as Object,e as EventArgs)
Public Event MyClick as MyControlEventHandler

2.

Public Event MyClick as EventHandler(Of EventArgs)

3.

Public Event MyClick(ByVal sender As Object,ByVal e As EventArgs)    

相关

  1. ASP.NET event stub not created as expected in Visual Studio
  2. Automatically create handler signature in Visual Studio

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)