Button获胜';t触发方法

本文关键字:方法 获胜 Button | 更新日期: 2023-09-27 18:01:04

Title确实说明了一切。我按下了按钮,却什么也没想明白为什么。

Default.aspx标记(表单范围内(

 <div class="form-group">
     <div style="text-align:center">
        <asp:Button input type="submit" class="btn btn-default btn-lg" align="center"  runat="server" OnClick="btnSubmit_Click" Text="Submit"/>
     </div>
 </div>

Default.aspx代码

 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection();
        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Connected to ASPX file');", true); 
        //...rest of code
    }

添加表单

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <%-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --%>
    <meta name="description" content="">
    <meta name="author" content="">
    <%--- Dependencies ---%>
    <link rel="stylesheet" href="./Content/bootstrap.min.css"/>
    <link rel="stylesheet" href="./Content/bootstrap-theme.min.css"/>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="./Content/ie10-viewport-bug-workaround.css" rel="stylesheet"/>
    <link href="./Content/starter-template.css" rel="stylesheet"/>
    <script src="./Scripts/ie-emulation-modes-warning.js"></script>
     <title>CCPOF</title>
</head>
  <body>
    <form class="form-horizontal" id="form1" runat="server">
    <div>

        <div class="form-group">
            <div style="text-align:center">
                <asp:Button class="btn btn-default btn-lg" align="center" runat="server" OnClick="btnSubmit_Click" Text="Submit"/> 
                <!--<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" CssClass="btn btn-default btn-lg" />
                    <asp:Button input type="submit" class="btn btn-default btn-lg" align="center"  runat="server" OnClick="btnSubmit_Click" Text="Submit"/> -->
            </div>
        </div>
        <br>
    </div>
    </form>
    <!-- Bootstrap core  JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="./Scripts/jquery-1.9.1.min.js"></script>
    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery-1.9.1.min.js"><'/script>')</script>
    <script src="./Scripts/bootstrap.min.js"></script>
    <script src="./Scripts/ie10-viewport-bug-workaround.js"></script>
    <embed id="embed_npfido" type="application/npfido" height="0"/>
</body>
</html>

Button获胜';t触发方法

为了结束这个问题,我正在写一个与OP沟通的答案(请参阅评论(

OP进行了几次更改,使其恢复了的功能

将按钮HTML更改为

<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" CssClass="btn btn-default btn-lg" />

将警报脚本更改为

ClientScript.RegisterClientScriptBlock(this.GetType(), "myalert", "<script>alert('Connected to ASPX file');</script>");

编辑:

我相信OP没有收到警报,因为他错过了<script>标签