ASP.Net UserControl, Event is created wrong

Multi tool use
Multi tool use


ASP.Net UserControl, Event is created wrong



A usercontrol that I created contains a and a wrapped inside a html button to get buttons with text and a icon. I want to be able to use them like normal so I'd like to have the possibility to suscribe to a click event in the aspx markup. So far so good, Visual Studio does create a void for me - but without the necessary arguments (object sender, EventArgs e).



You find codesnippets below:



IconButton.ascx:


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IconButton.ascx.cs" Inherits="Namespace.Controls.IconButton" %>
<button runat="server" id="btnWrapper" class="iconButton" onserverclick="btnWrapper_ServerClick">
<asp:Label runat="server" ID="lblContent">
<%= this.Content %>
</asp:Label>
<i class="material-icons" id="icon" runat="server"><%= this.MaterialIconName %> </i>
</button>`



IconButton.ascx.cs:


public partial class IconButton : System.Web.UI.UserControl
{
public delegate void ClickEvent(object sender, System.EventArgs e);

public string MaterialIconName { get; set; }
public string Content { get; set; }

public event ClickEvent ButtonClick;


protected virtual void OnButtonClick(object sender, EventArgs e)
{
if (ButtonClick != null)
{
ButtonClick(sender, e);
}
}

protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnWrapper_ServerClick(object sender, EventArgs e)
{
this.OnButtonClick(sender, e);
}
}



Usage in a WebForm:


<ctrl:IconButton ID="btnSearch2" runat="server" MaterialIconName="search" Content="Suche" OnButtonClick="btnSearch2_ButtonClick" />



The event / void created by visual studio:


protected void btnSearch2_ButtonClick()
{

}



What I want it to create:


protected void btnSearch2_ButtonClick(object sender, EventArgs e)
{

}



I am aware that I could just edit the method definitions myself and I would absolutely have no problem with it. But since it isn't just me who works on the project and I don't want to have to explain this ugly behaviour to everyone I'd love to work this out.



Any ideas very appreciated!









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

NlMBItEhbXBy rB2Je5wJXvLdEge9piSdNSbQJbKbFgCU9jOXIm9Yt5Rk,Dd93lEww
KF4LoN7PFXEgk T Eq7gEFyz zlrR9NITQ4pd7xYvDj9jio,VllB,n

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications