Tom Gullen
Tom Gullen

Reputation: 61729

ASP.net c# question on forms

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.

Upvotes: 2

Views: 229

Answers (2)

statenjason
statenjason

Reputation: 5180

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.

Upvotes: 4

Burt
Burt

Reputation: 7758

Try this:

protected void regSubmit(object sender, EventArgs e)

Upvotes: 6

Related Questions