简体   繁体   中英

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.

尝试这个:

protected void regSubmit(object sender, EventArgs e)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM