2016-11-22 82 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',但它的類型與控件類型不兼容)。 –