Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How come my event handling is not working? I'm getting this error. I'm running VS 2008 / .NET 3.5 SP1 / Win XP, and, just in case the source code is available here.

Error 1 No overload for 'InsertButton_Click' matches delegate 'System.EventHandler' c:\inetpub\wwwroot\Jon's Couch\Articles.aspx.cs 21 31 http://localhost/Jon's Couch/


Articles.aspx
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Articles.aspx.cs" Inherits="Articles" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <title>@Jon's</title>
</head>
<body>
    <form id="form1" runat="server">
    <h1>@Jon's <img src="images/sofa.jpg" alt="logo"/> </h1 >
    <div style="float:left;width:122px">
        <p style="width: 122px; height: 663px; margin-top: 0px; margin-right: 0px;">
        <a href="About.aspx">About me</a> <br />
        <a href="Diary.aspx">My diary</a> <br />
        <a href="Articles.aspx">Articles</a> <br />
        <a href="Bookmarks.aspx">My bookmarks</a> <br />
        <a href="Promotions.aspx">Promotions</a> <br />
        <a href="Resume.aspx">My resume</a> <br />
        <a href="Warez.aspx">Filesharing</a> <br />
        </p>
      </div>
   <div>
   <asp:FormView ID="Envelope" runat="server" DataSourceID="SqlDataSource1"
            AllowPaging="True">
        <HeaderTemplate>
        </HeaderTemplate>
        <EditItemTemplate>
            Timestamp:
            <asp:TextBox ID="TimestampTextBox" runat="server"
                Text='<%# Bind("Timestamp") %>' />
            <br />
            Subject:
            <asp:TextBox ID="SubjectTextBox" runat="server" Text='<%# Bind("Subject") %>' />
            <br />
            EntryText:
            <asp:TextBox ID="EntryTextTextBox" runat="server"
                Text='<%# Bind("EntryText") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
                CommandName="Update" Text="Update" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            <asp:Button ID="Edit" runat="server" Text="Edit" CommandName="edit" /> <br />
            <asp:Button ID="New" runat="server" Text="New" CommandName="new" /> <br />
        </EditItemTemplate>
         <InsertItemTemplate>
             Timestamp:
             <asp:TextBox ID="TimestampTextBox" runat="server"
                 Text='<%# Bind("Timestamp") %>' />
             <br />
             Subject:
             <asp:TextBox ID="SubjectTextBox" runat="server" Text='<%# Bind("Subject") %>' />
             <br />
             EntryText:
             <asp:TextBox ID="EntryTextTextBox" runat="server"
                 Text='<%# Bind("EntryText") %>' />
             <br />
             <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
                 CommandName="Insert" Text="Insert" OnClick="InsertButton_Click" />
             &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"
                 CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </InsertItemTemplate>
        <ItemTemplate>
            Timestamp:
            <asp:Label ID="TimestampLabel" runat="server" Text='<%# Bind("Timestamp") %>' />
            <br />
            Subject:
            <asp:Label ID="SubjectLabel" runat="server" Text='<%# Bind("Subject") %>' />
            <br />
            EntryText:
            <asp:Label ID="EntryTextLabel" runat="server" Text='<%# Bind("EntryText") %>' />
            <br />
        </ItemTemplate>
 </asp:FormView>
     <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:couch_dbConnectionString %>"
                SelectCommand="SELECT [Timestamp], [Subject], [EntryText] FROM [Article]"
                UpdateCommand="UPDATE [Article] SET [Timestamp] = @Timestamp, [Subject] = @Subject, [EntryText] = @EntryText"
                InsertCommand="INSERT INTO [Article] ([EntryID], [Timestamp], [Subject], [EntryText]) VALUES @EntryID, @Timestamp, @Subject, [EntryText]">
           </asp:SqlDataSource>
   </div>
</form>
</body>
</html>




Articles.aspx.cs
C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;
public partial class Articles : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "Jon's Couch";
    }
    protected delegate EventHandler InsertButton_Click (object sender, FormViewCommandEventArgs e);
    InsertButton_Click += new System.EventHandler(this.InsertButton_Click);
    protected void InsertButton_Click(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "new")
        {
            Envelope.DefaultMode = FormViewMode.Insert;
        }
    }
}


:confused:
Posted
Updated 27-Jun-16 23:51pm
v2
Comments
koool.kabeer 4-Sep-10 6:31am    
i think you are trying something new....
jon-80 4-Sep-10 6:40am    
What's the correct way?
koool.kabeer 4-Sep-10 6:48am    
what is your actual requirement?
Member 13928033 3-Oct-18 5:18am    
didnt work

Is it a typo? Shouldn't this line

InsertButton_Click += new System.EventHandler(this.InsertButton_Click);

be moved to the possibly the Page_Load event or even the Pre_Init?
 
Share this answer
 
Comments
Abhishek Sur 4-Sep-10 12:33pm    
I think ASP.NET can easily do this without even specifying this event handler. Just specifying the EventHandler in ASPX page will be a better approach.
But this should definitely be within Page_Load. One cannot run expression outside any method.

Got my 5 Mark.
jon-80 4-Sep-10 12:47pm    
Would you please add a code snippet or a link to a related article as an example?
jon-80 4-Sep-10 12:49pm    
My actual requirement is to have a <formview> that somehow binds to a datasource (SQL Server 2005), and, allows the user to read, edit, insert, update and delete from the form. If a form is not available, some kind of <textbox> or interface is good enough. This is really basic, I just can't figure out how to do it in ASP.NET.
use System.Eventargs e. It will solve your problem.... Like...

private void button1_Click(object sender, System.EventArgs e)
{

}
 
Share this answer
 
Comments
Member 10044316 19-Oct-14 18:40pm    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900