英文:
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> 
<button runat="server" onserverclick="Click_Edit">Update</button> 
</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
<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
<%--<button style="width: 90px; height: 40px;" runat="server" onserverclick="Click_Delete" value="delete">Delete</button>&nbsp
<button style="width: 90px; height: 40px;" runat="server" onserverclick="Edit" value="update">Update</button>--%>
<%--<input type="button" value="Delete" name="btnDelete" id="btnDelete" runat="server" />
<input type="button" value="Update" name="btnUpdate" id="btnUpdate" runat="server" />--%>
</div> <br />
<div id="tableDiv" runat="server" style="border: 1px;">
</div>
<P runat="server" id="mess"></P>
</form>
delete.aspx.cs
public partial class DeleteUpdate : System.Web.UI.Page
{
//public string BuildUsersTable(DataTable dt)
//{
// string str = "<table class= 'usersTable' align='center'>";
//}
public string st = "";
public string msg = "";
public string sqlDelete = "";
public void Click_Delete(object sender, EventArgs e)
{
int userId;
List<int> usersList = new List<int>();
for (int i = 1; i < Request.Form.Count; i++)
{
if (Request.Form.AllKeys[i].Contains("chk"))
{
userId = int.Parse(Request.Form.AllKeys[i].Remove(0, 3));
usersList.Add(userId);
}
}
int[] userIdToDelete = usersList.ToArray();
Helper.Delete(userIdToDelete);
string SQLStr = "SELECT * FROM " + 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 < Request.Form.Count; i++)
{
if (Request.Form.AllKeys[i].Contains("chk"))
{
Session["userToUpdate"] = int.Parse(Request.Form.AllKeys[i].Remove(0, 3));
Response.Redirect("/pages/UpdateAdmin.aspx");
}
}
mess.InnerHtml = "No user was selscted to edit!";
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Login"] != null)
{
if (!(bool)Session["Admin"])
{
Response.Redirect("Home.aspx");
}
else
{
if (!IsPostBack)
{
string SQLStr = "SELECT * FROM " + 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.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论