2016-11-22 130 views
0

我在onserverclick事件中遇到问题。我在tab_1中创建的HTML服务器端按钮 “btnSubmit按钮”:HTML按钮onserverclick在asp.net中不工作

<%@ 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'.

+0

变化onserverclick到的OnClick –

+0

仍然无法正常工作。和OnClick只是为asp工作:Button –

+0

为什么不使用'asp:Button'? – VDWWD

回答

1

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

从解决方案资源管理器窗口中,右键单击您的解决方案,并选择清洁液,然后重建解决方案

和格式化元素是这样

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

对不起,你是什么意思? –

+0

从解决方案资源管理器菜单,以任何方式编辑我的答案全部细节 – iceDragon

+0

我仍然收到错误'内容不允许在元素输入的开始和结束标记之间“。 –

0

你可以试试 “input type ='button'” 改为“button”?

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

无法正常工作。它是asp运行时错误(基类包含字段'btnsubmit',但它的类型与控件类型不兼容)。 –