2

Trying to create a simple form:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="register.aspx.cs" Inherits="AlphaPack._Default"
    MasterPageFile="MasterPages/Main.master"
    title="Hi there!"
%>

<script runat="server">
    public void regSubmit()
    {
        statusLabel.Text = "Submitted!";
    }
</script>

<asp:content id="Content1" contentplaceholderid="mainContent" runat="server">


<form id="registerForm" runat="server">

<asp:Label runat="server" id="statusLabel"></asp:Label>
<asp:Button id="id" text="Register" OnClick="regSubmit" runat="server" />

</form>

</asp:content>

hope it's obvious what I'm trying to do, someone clicks the button and it submits the form and changes the label text.

Compiler Error Message: CS0123: No overload for 'regSubmit' matches delegate 'System.EventHandler'

I know I'm doing something fundamentally wrong here, i'm new to .net moving over from classic ASP.

1
  • 1
    In addition to the answers, I'd recommend using the codebehind file and letting the IDE fill some of this in for you - stops you from falling foul of little problems like this. Commented Aug 5, 2010 at 13:17

2 Answers 2

6

Try this:

protected void regSubmit(object sender, EventArgs e)
Sign up to request clarification or add additional context in comments.

1 Comment

@Tom: For the record, all events in .NET have two arguments: an Object (whose event it is) and an EventArgs instance (or one of its subclasses).
4

Because it's an event handler, your click method needs to have the proper signature of

public void regSubmit(object sender, EventArgs e)

Jon Skeet wrote an article on understanding Delegates and Events. Going over that may help you with these sort of issues in the future.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.