asp:按钮不起作用

时间:2015-04-16 14:19:06

标签: c# html asp.net webforms

我有一个简单的按钮,点击时应该在标签中显示文字。但是当我按下按钮时,没有任何反应。我可能会出错的任何想法?

Default.aspx的:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default"%>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Button ID="testbutton" runat="server" Text="Button" OnClick="testbutton_Click" />
    <asp:Label ID="testlabel" runat="server"></asp:Label>
</asp:Content>

Default.aspx.cs:

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

using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

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

    }
    protected void testbutton_Click(object sender, EventArgs e)
    {
        testlabel.Text = "You clicked the Testbutton";  
    }
}

主页:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>PhotoChunk</title>
    <link href="css/bootstrap.css" rel='stylesheet' type='text/css' />
    <link href="css/style.css" rel='stylesheet' type='text/css' />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'/>
    <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<script src="js/jquery.min.js"></script>
<!--<script src="js/jquery.easydropdown.js"></script>-->
<!--start slider -->
<link rel="stylesheet" href="css/fwslider.css" media="all" />
<script src="js/jquery-ui.min.js"></script>
<script src="js/fwslider.js"></script>
<!--end slider -->
<script type="text/javascript">
        $(document).ready(function() {
            $(".dropdown img.flag").addClass("flagvisibility");

            $(".dropdown dt a").click(function() {
                $(".dropdown dd ul").toggle();
            });

            $(".dropdown dd ul li a").click(function() {
                var text = $(this).html();
                $(".dropdown dt a span").html(text);
                $(".dropdown dd ul").hide();
                $("#result").html("Selected value is: " + getSelectedValue("sample"));
            });

            function getSelectedValue(id) {
                return $("#" + id).find("dt a span.value").html();
            }

            $(document).bind('click', function(e) {
                var $clicked = $(e.target);
                if (! $clicked.parents().hasClass("dropdown"))
                    $(".dropdown dd ul").hide();
            });


            $("#flagSwitcher").click(function() {
                $(".dropdown img.flag").toggleClass("flagvisibility");
            });
        });
     </script>
      <!----details-product-slider--->
                <!-- Include the Etalage files -->
                    <link rel="stylesheet" href="css/etalage.css" />
                    <script src="js/jquery.etalage.min.js"></script>
                <!-- Include the Etalage files -->
                <script>
                        jQuery(document).ready(function($){

                            $('#etalage').etalage({
                                thumb_image_width: 600,
                                thumb_image_height: 400,

                                show_hint: true,
                                click_callback: function(image_anchor, instance_id){
                                    alert('Callback example:\nYou clicked on an image with the anchor: "'+image_anchor+'"\n(in Etalage instance: "'+instance_id+'")');
                                }
                            });
                            // This is for the dropdown list example:
                            $('.dropdownlist').change(function(){
                                etalage_show( $(this).find('option:selected').attr('class') );
                            });

                    });
                </script>
                <!----//details-product-slider--->
         <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>

<body>
      <form id="form1" runat="server">
        <div class="header">
        <div class="container">
            <div class="row">
              <div class="col-md-12">
                 <div class="header-left">
                     <div class="logo">
                        <a href="Default.aspx"><img src="images/logowhite.png" alt=""/></a>
                     </div>
                     <div class="menu">
                          <a class="toggleMenu" href="#"><img src="images/nav.png" alt="" /></a>
                            <ul class="nav" id="nav">
                                <li><a href="Browse.aspx">Browse</a></li>
                                <li><a href="Upload.aspx">Upload</a></li>
                                <li><a href="Upload.aspx">About</a></li>                            

                            </ul>
                            <script type="text/javascript" src="js/responsive-nav.js"></script>
                    </div>                          
                    <div class="clear"></div>
                </div>
                <div class="header_right">
                  <!-- start search-->
                      <div class="search-box">
                            <div id="sb-search" class="sb-search">
                                <form>
                                    <input class="sb-search-input" placeholder="What are you looking for?" type="search" name="search" id="search">
                                    <input class="sb-search-submit" type="submit" value="">
                                    <span class="sb-icon-search"> </span>
                                </form>
                            </div>
                        </div>
                        <!----search-scripts---->
                        <script src="js/classie.js"></script>
                        <script src="js/uisearch.js"></script>
                        <script>
                            new UISearch(document.getElementById('sb-search'));
                        </script>
                        <!----//search-scripts---->
                    <ul class="icon1 sub-icon1 profile_img">
                     <li><a class="active-icon c1" href="#"> </a>
                        <ul class="sub-icon1 list">
                          <li class="list_img"><img src="images/1.jpg" alt=""/></li>
                                                  <li class="list_desc"><h4><a href="#">Matthew Thompson</a></h4></li>
                                                  <li><div class="login_buttons">
                             <div class="check_button"><a href="#">Account</a></div>
                             <div class="login_button"><a href="Login.aspx">Logout</a></div>
                          </div>
                          <div class="clear"></div>
                                                  </li>
                        </ul>
                     </li>
                   </ul>
                   <div class="clear"></div>
           </div>
          </div>
         </div>
        </div>
    </div>

    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
 <div class="footer">
            <div class="container">
                <div class="row">
                    <div class="col-md-3">
                        <ul class="footer_box">
                            <h4>About PhotoChunk</h4>
                                                        <li><a href="#">About Us</a></li>
                                                        <li><a href="#">Privacy Policy</a></li>
                        </ul>
                    </div>
                    <div class="col-md-3">
                        <ul class="footer_box">
                            <h4>Support</h4>
                            <li><a href="#">Contact Us</a></li>
                            <li><a href="#">Help</a></li>
                        </ul>
                    </div>
                    <div class="col-md-3">
                        <ul class="footer_box">
                            <ul class="social"> 
                              <li class="facebook"><a href="#"><span> </span></a></li>
                              <li class="twitter"><a href="#"><span> </span></a></li>
                              <li class="instagram"><a href="#"><span> </span></a></li> 
                              <li class="pinterest"><a href="#"><span> </span></a></li> 
                              <li class="youtube"><a href="#"><span> </span></a></li>                                                       
                            </ul>

                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

我能够让它发挥作用!

通过删除母版页中的额外表格标签,该按钮现在可以正常工作。

        <div id="sb-search" class="sb-search">
                <form>
                    <input class="sb-search-input" placeholder="What are you looking for?" type="search" name="search" id="search">
                    <input class="sb-search-submit" type="submit" value="">
                    <span class="sb-icon-search"> </span>
                </form>
            </div>