本文介绍了HTML按钮onserverclick在asp.net中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在onserverclick事件中遇到了问题.我已经在tab_1中创建了HTML服务器端按钮"btnsubmit":

I had a problem in the event onserverclick. I have created an HTML server-side button "btnsubmit" in tab_1:

<%@ 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");
        }

    }
}

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

When Pressing the button I get the following Error:

更新:清洁解决方案并重建它之后,我出现以下错误:

Update:After cleaning the solution and rebuilding it I had the following error:

推荐答案

在解决方案资源管理器"窗口中,右键单击您的解决方案,然后选择清洁解决方案",然后重新生成解决方案

From Solution Explorer window, right click on your solution and choose Clean solution and then rebuild solution

并设置元素格式如下

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

这篇关于HTML按钮onserverclick在asp.net中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 06:07