“No overload for ‘Click_Edit’ matches delegate ‘EventHandler'”

huangapple go评论58阅读模式
英文:

Why is it write: "No overload for 'Click_Edit' matches delegate 'EventHandler'"

问题

I'm trying to build a site in HTML. I already built a registry, login, home, and created a table of all the people who have subscribed to my site. Now, I want an option that allows me to delete and update my table of users. However, it's showing me the error "No overload for 'Click_Edit' matches delegate 'EventHandler'" for the buttons. In either case, the buttons are not working.

Here's the relevant code:

<form id="deleteForm" method="post" runat="server">
    <div style="margin-left:15px; margin-top:20px;">
        <button runat="server" onserverclick="Click_Delete">Delete</button>&nbsp
        <button runat="server" onserverclick="Click_Edit">Update</button>&nbsp
    </div>
    <!-- ... -->
</form>

In the code-behind (delete.aspx.cs):

public partial class DeleteUpdate : System.Web.UI.Page
{
    // ...

    public void Click_Delete(object sender, EventArgs e)
    {
        // ...
    }

    public void Click_Edit(object sender, EventArgs e)
    {
        // ...
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        // ...
    }
}

Please note that the error you're encountering might be due to the event handler signature not matching the expected EventHandler delegate. You should ensure that the Click_Edit method's signature matches the EventHandler delegate to resolve this issue.

英文:

I'm trying to build a site in html. I already build registery, login, home and did a table of all the people who have been subscribe to my site. now, I want an option that I can delete and update my table of users. now, it writes me "No overload for 'Click_Edit' matches delegate 'EventHandler'", about the buttens. This or that way, the buttens are not working.

deleteapdate.aspx

&lt;form id=&quot;deleteForm&quot; method=&quot;post&quot; runat=&quot;server&quot;&gt;
&lt;div style=&quot;margin-left:15px; margin-top:20px;&quot;&gt;

    &lt;button runat=&quot;server&quot; onserverclick=&quot;Click_Delete&quot;&gt;Delete&lt;/button&gt;&amp;nbsp
    &lt;button  runat=&quot;server&quot; onserverclick=&quot;Click_Edit&quot;&gt;Update&lt;/button&gt;&amp;nbsp
    &lt;%--&lt;button style=&quot;width: 90px; height: 40px;&quot; runat=&quot;server&quot; onserverclick=&quot;Click_Delete&quot; value=&quot;delete&quot;&gt;Delete&lt;/button&gt;&amp;nbsp
    &lt;button style=&quot;width: 90px; height: 40px;&quot;  runat=&quot;server&quot; onserverclick=&quot;Edit&quot; value=&quot;update&quot;&gt;Update&lt;/button&gt;--%&gt;


    &lt;%--&lt;input type=&quot;button&quot; value=&quot;Delete&quot; name=&quot;btnDelete&quot; id=&quot;btnDelete&quot; runat=&quot;server&quot;  /&gt;
    &lt;input type=&quot;button&quot; value=&quot;Update&quot; name=&quot;btnUpdate&quot; id=&quot;btnUpdate&quot; runat=&quot;server&quot;  /&gt;--%&gt;

    &lt;/div&gt; &lt;br /&gt;








    &lt;div id=&quot;tableDiv&quot; runat=&quot;server&quot; style=&quot;border: 1px;&quot;&gt;

    &lt;/div&gt;
    &lt;P runat=&quot;server&quot; id=&quot;mess&quot;&gt;&lt;/P&gt;
    &lt;/form&gt;

delete.aspx.cs

 public partial class DeleteUpdate : System.Web.UI.Page
{
    //public string BuildUsersTable(DataTable dt)
    //{
    //    string str = &quot;&lt;table class= &#39;usersTable&#39; align=&#39;center&#39;&gt;&quot;;
    //}
    public string st = &quot;&quot;;
    public string msg = &quot;&quot;;
    public string sqlDelete = &quot;&quot;;

    public void Click_Delete(object sender, EventArgs e)
    {
        int userId;
        List&lt;int&gt; usersList = new List&lt;int&gt;();
        for (int i = 1; i &lt; Request.Form.Count; i++)
        {
            if (Request.Form.AllKeys[i].Contains(&quot;chk&quot;))
            {
                userId = int.Parse(Request.Form.AllKeys[i].Remove(0, 3));
                usersList.Add(userId);
            }
        }
        int[] userIdToDelete = usersList.ToArray();
        Helper.Delete(userIdToDelete);

        string SQLStr = &quot;SELECT * FROM &quot; + Helper.tblname;
        DataSet ds = Helper.RetrieveUsersTable(SQLStr);
        string table = Helper.BuildUsersTable(ds.Tables[0]);
        tableDiv.InnerHtml = table;
    }

    public void Click_Edit(ObjectStateFormatter sender, EventArgs e)
    {
        for (int i = 1; i &lt; Request.Form.Count; i++)
        {
            if (Request.Form.AllKeys[i].Contains(&quot;chk&quot;))
            {
                Session[&quot;userToUpdate&quot;] = int.Parse(Request.Form.AllKeys[i].Remove(0, 3));
                Response.Redirect(&quot;/pages/UpdateAdmin.aspx&quot;);
            }
        }
        mess.InnerHtml = &quot;No user was selscted to edit!&quot;;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[&quot;Login&quot;] != null)
        {
            if (!(bool)Session[&quot;Admin&quot;])
            {
                Response.Redirect(&quot;Home.aspx&quot;);
            }
            else
            {

                if (!IsPostBack)
                {

                    string SQLStr = &quot;SELECT * FROM &quot; + Helper.tblname;
                    DataSet ds = Helper.RetrieveUsersTable(SQLStr);
                    DataTable dt = ds.Tables[Helper.tblname];
                    string table = Helper.BuildUsersTable(dt);
                    tableDiv.InnerHtml = table;
                }
            }
        }
    }

答案1

得分: 1

使用 public void Click_Edit(object sender, EventArgs e) 作为函数定义。您的方法必须接收 sender 参数作为对象类型,以匹配 EventHandler 委托的定义。

(您会注意到所有其他事件处理程序也都使用相同的格式。)

英文:

Use public void Click_Edit(object sender, EventArgs e) for the function definition. Your method must receive the sender parameter as object type to match the EventHandler delegate definition.

(You will notice that all your other event handlers also use this same format.)

huangapple
  • 本文由 发表于 2023年7月4日 21:19:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76613069.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定