HTML 按钮 onserverclick 在 asp.net 中不起作用

HTML button onserverclick is not working in asp.net

我在服务器点击事件中遇到了问题。我在 tab_1:

中创建了一个 HTML 服务器端按钮 "btnsubmit"
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Skripsi.Home" %>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Home</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

    <div class="container-fluid bg-1 text-center">
        <img src="/Image/fti-untar.png" alt="untar" />
        <h2>Layanan</h2>
        <br />
    </div>

    <div class="container">
        <ul class="nav nav-pills nav-stacked col-md-2">
          <li class="active"><a href="#tab_1" data-toggle="pill">Home</a></li>
          <li><a href="#tab_2" data-toggle="pill">Biodata</a></li>
          <li><a href="#tab_3" data-toggle="pill">Konsultasi</a></li>
          <li><a href="#tab_4" data-toggle="pill">Hasil Studi</a></li>
        </ul>
        <div class="tab-content col-md-10">
            <div class="tab-pane active" id="tab_1" runat="server">
                <div id="panel1" class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">Biodata</h3>
                    </div>
                    <div class="panel-body">
                        <label for="id">ID</label>
                        <input type="text" id="txtid" class="form-control" runat="server"/>
                        <br />
                        <label for="nama">Nama</label>
                        <input type="text" id="txtnama" class="form-control" />
                        <br />
                        <label for="email">Email</label>
                        <input type="text" id="txtemail" class="form-control" />
                        <br />
                        <label for="alamat">Alamat</label>
                        <input type="text" id="txtalamat" class="form-control" />
                        <input type="button" id="btnsubmit" runat="server" class="btn btn-default" onserverclick="btnsubmit_ServerClick">Submit</input>
                    </div>
                </div>
            </div>

            <div class="tab-pane" id="tab_2">
                                <div class="col-xs-3">
                    <input type="text" id="txtname" name="Name" value="" class="form-control"/>
                </div>
                <h4>Pane B</h4>
            <p>Pellentesque habitant morbi tristique senectus et netus et malesuada famesac turpis egestas.</p>
            </div>
            <div class="tab-pane" id="tab_3">
                <h4>Pane C</h4>
                <p>Pellentesque habitant morbi tristique senectus et netus et malesuada famesac turpis egestas.</p>
            </div>
            <div class="tab-pane" id="tab_4">
                <h4>Pane D</h4>
                <p>Pellentesque habitant morbi tristique senectus et netus et malesuada famesac turpis egestas.</p>
            </div>

        </div><!-- tab content -->
    </div><!-- end of container -->
</body>
</html>

后面的代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Skripsi
{
    public partial class Home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnsubmit_ServerClick(object sender, EventArgs e)
        {
            Response.Write("Success Horray");
        }

    }
}

按下按钮时出现以下错误:

asp runtime error(the base class includes the field 'btnsubmit', but it's type is not compatible with the type of control)

更新: 清理并重建解决方案后,出现以下错误:

'content is not allowed between the opening and closing tags for element input'.

你能试试吗 "input type='button' " 相反 "button" ?

<button id="btnsubmit" runat="server" class="btn btn-default" onserverclick="btnsubmit_ServerClick">Submit</button>

it's asp runtime error(the base class includes the field 'btnsubmit', but it's type is not compatible with the type of control)

在解决方案资源管理器 window 中,右键单击您的解决方案并选择清理解决方案,然后重建解决方案

并将元素格式化成这样

<input type="button" id="btnsubmit" runat="server" class="btn btn-default" onserverclick="btnsubmit_ServerClick" value="Submit" />