按钮没有响应其点击事件?

时间:2013-09-09 13:23:45

标签: asp.net c#-4.0 button webforms

我已经拖动了一个按钮并对其点击事件进行了编码,但它没有响应。 我已插入断点但对按钮单击没有影响。点击按钮没有任何反应。 我的代码是

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="css/images/favicon.ico" />
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
    <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.jcarousel.min.js"></script>
    <!--[if IE 6]>
        <script type="text/javascript" src="js/png-fix.js"></script>
    <![endif]-->
    <script type="text/javascript" src="js/functions.js"></script>
    <link type="text/css" href="menu_assets/styles.css" rel="stylesheet" />
    <!-- Attach our CSS -->
        <link rel="stylesheet" href="reveal.css"/>  

        <!-- Attach necessary scripts -->
        <!-- <script type="text/javascript" src="jquery-1.4.4.min.js"></script> -->
        <script type="text/javascript" src="jquery.reveal.js"></script>

        <style type="text/css">
            body { font-family: "HelveticaNeue","Helvetica-Neue", "Helvetica", "Arial", sans-serif; }
            .big-link { display:block; margin-top: 100px; text-align: center; font-size: 70px; color: #06f; }
        </style>
        <style type="text/css">



        /*------------------------------*/

        #signup {
            width: 480px;
            height: auto;
            margin: 10px auto 10px auto;
            padding: 20px;
            position: relative;
            background: #fff url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAECAMAAAB883U1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAlQTFRF7+/v7u7u////REBVnAAAAAN0Uk5T//8A18oNQQAAABZJREFUeNpiYGJiYmBiYgRiBhAGCDAAALsAFJhiJ+UAAAAASUVORK5CYII=);
            border: 1px solid #ccc;
            -moz-border-radius: 3px;
            -webkit-border-radius: 3px; 
            border-radius: 3px;  
        }

        #signup::before, 
        #signup::after {
            content: "";
            position: absolute;
            bottom: -3px;
            left: 2px;
            right: 2px;
            top: 0;
            z-index: -1;
            background: #fff;
            border: 1px solid #ccc;         
        }

        #signup::after {
            left: 4px;
            right: 4px;
            bottom: -5px;
            z-index: -2;
            -moz-box-shadow: 0 8px 8px -5px rgba(0,0,0,.3);
            -webkit-box-shadow: 0 8px 8px -5px rgba(0,0,0,.3);
            box-shadow: 0 8px 8px -5px rgba(0,0,0,.3);
        }

        /*------------------------------*/

        #signup h1 {
            position: relative;
            font: italic 1em/3.5em 'trebuchet MS',Arial, Helvetica;
            color: #fff;
            background-color:#7cbfff;
            text-align: center;
            margin: 0 0 20px;
            -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset;
            -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset;
        }

        #signup h1::before,
        #signup h1::after{
            content:'';
            position: absolute;
            border: 1px solid rgba(0,0,0,.15);
            top: 10px;
            bottom: 10px;
            left: 0;
            right: 0;
        }

        #signup h1::after{
            top: 0;
            bottom: 0;
            left: 10px;
            right: 10px;
        }

        /*------------------------------*/

        ::-webkit-input-placeholder {
           color: #bbb;
        }

        :-moz-placeholder {
           color: #bbb;
        }                       

        .placeholder{
            color: #bbb; /* polyfill */
        }       

        #signup input{
            margin: 5px 0;
            padding: 15px;
            width: 100%;
            *width: 518px;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            border: 1px solid #ccc;
            -moz-border-radius: 3px;
            -webkit-border-radius: 3px;
            border-radius: 3px; 
        }
            #signup select{
            margin: 5px 0;
            padding: 15px;
            width: 100%;
            *width: 518px;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            border: 1px solid #ccc;
            -moz-border-radius: 3px;
            -webkit-border-radius: 3px;
            border-radius: 3px; 
        }


        #signup input:focus{
            outline: 0;
            border-color: #aaa;
            -moz-box-shadow: 0 2px 1px rgba(0, 0, 0, .3) inset;
            -webkit-box-shadow: 0 2px 1px rgba(0, 0, 0, .3) inset;
            box-shadow: 0 2px 1px rgba(0, 0, 0, .3) inset;
        }   
        #signup select:focus{
            outline: 0;
            border-color: #aaa;
            -moz-box-shadow: 0 2px 1px rgba(0, 0, 0, .3) inset;
            -webkit-box-shadow: 0 2px 1px rgba(0, 0, 0, .3) inset;
            box-shadow: 0 2px 1px rgba(0, 0, 0, .3) inset;
        }       

        #signup button , #signup input[type=submit]{
            margin: 20px 0 0 0;
            padding: 15px 8px;          
            width: 100%;
            cursor: pointer;
            border: 1px solid #2493FF;
            overflow: visible;
            display: inline-block;
            color: #fff;
            font: bold 1.4em arial, helvetica;
            text-shadow: 0 -1px 0 rgba(0,0,0,.4);         
            background-color: #2493ff;
            background-image: -webkit-gradient(linear, left top, left bottom, from(rgba(255,255,255,.5)), to(rgba(255,255,255,0)));
            background-image: -webkit-linear-gradient(top, rgba(255,255,255,.5), rgba(255,255,255,0));
            background-image: -moz-linear-gradient(top, rgba(255,255,255,.5), rgba(255,255,255,0));
            background-image: -ms-linear-gradient(top, rgba(255,255,255,.5), rgba(255,255,255,0));
            background-image: -o-linear-gradient(top, rgba(255,255,255,.5), rgba(255,255,255,0));
            background-image: linear-gradient(top, rgba(255,255,255,.5), rgba(255,255,255,0));
            -webkit-transition: background-color .2s ease-out;
            -moz-transition: background-color .2s ease-out;
            -ms-transition: background-color .2s ease-out; 
            -o-transition: background-color .2s ease-out;  
            transition: background-color .2s ease-out;
            -moz-border-radius: 3px;
            -webkit-border-radius: 3px;
            border-radius: 3px;
            -moz-box-shadow:  0 2px 1px rgba(0, 0, 0, .3),
                              0 1px 0 rgba(255, 255, 255, .5) inset;
            -webkit-box-shadow: 0 2px 1px rgba(0, 0, 0, .3),
                                0 1px 0 rgba(255, 255, 255, .5) inset;
            box-shadow: 0 2px 1px rgba(0, 0, 0, .3),
                        0 1px 0 rgba(255, 255, 255, .5) inset;                                    
        }

        #signup button , #signup input[type=submit]:hover{
            background-color: #7cbfff;
            border-color: #7cbfff;
        }

        #signup button , #signup input[type=submit]:active{
            position: relative;
            top: 3px;
            text-shadow: none;
            -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset;
            -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset;
            box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset;
        }

        /* ------------------------------------------------- */

        #about{
            color: #999;
            text-align: center;
            font: 0.9em Arial, Helvetica;
        }

        #about a{
            color: #777;
        }       
    </style>
    <script language="javascript">
        function test() {
            alert('Hello');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <!-- Header -->
        <div id="header" class="shell">
            <div id="logo">
                <h1>
                    <a href="#">BestSeller</a></h1>
                <span><a href="#">free css template</a></span>
            </div>
            <!-- Navigation -->
            <div id="navigation">
                <ul>
                    <li><a href="#" class="active">Home</a></li>
                    <li><a href="#">Products</a></li>
                    <li><a href="#">Promotions</a></li>
                    <li><a href="#">Profile</a></li>
                    <li><a href="#">About Us</a></li>
                    <li><a href="#">Contacts</a></li>
                </ul>
            </div>
            <!-- End Navigation -->
            <div class="cl">
                &nbsp;</div>
            <!-- Login-details -->
            <div id="login-details">
                <p>
                    <a href="#" id="A1" data-reveal-id="myModal">Login  </a> ..</p>
                <p>
                <p>
                    Welcome, <a href="#" id="user">Guest</a> .</p>
                <p>
                    <a href="#" class="cart">
                        <img src="css/images/cart-icon.png" alt="" /></a>Shopping Cart (0) <a href="#" class="sum">
                            $0.00</a>
                </p>
            </div>
            <!-- End Login-details -->
        </div>
        <!-- End Header -->

        <!-- Slider -->
        <div id="slider">
            <div class="shell">
                <ul>
                    <li>
                        <div class="image">
                            <img src="css/images/so0.png" alt="" />
                        </div>
                        <div class="details">
                            <h2>
                                ClickDesire</h2>
                            <h3>
                                Special Offers</h3>
                            <p class="title">
                                Get Upto 50% Discount on Purchase worth Rs. 1999. or More</p>
                            <p class="description">
                                This Season Purchase any Desired Shoes and Save upto 50%</p>
                            <a href="#" class="read-more-btn">Read More</a>
                        </div>
                    </li>
                    <li>
                        <div class="image">
                            <img src="css/images/so1.png" alt="" />
                        </div>
                        <div class="details">
                            <h2>
                                ClickDesire
                            </h2>
                            <h3>
                                Special Offers</h3>
                            <p class="title">
                                Flat 50% off + Extxa 10% on Purchase of Formal Wear</p>
                            <p class="description">
                                This Season ClickDesire brought an exciting offer<br />
                                On Purchase of any <b>Men</b> or<b>Women</b> Formal Wear<br />
                                Get 10% extra Discount</p>
                            <a href="#" class="read-more-btn">Read More</a>
                        </div>
                    </li>
                    <li>
                        <div class="image">
                            <img src="css/images/so2.png" alt="" />
                        </div>
                        <div class="details">
                            <h2>
                                ClickDesire
                            </h2>
                            <h3>
                                Special Offers</h3>
                            <p class="title">
                                Buy 1 Get 1 Free</p>
                            <p class="description">
                                Buy any Bed Sheet and get 50% on 2nd BedSheet</p>
                            <a href="#" class="read-more-btn">Read More</a>
                        </div>
                    </li>
                    <li>
                        <div class="image">
                            <img src="css/images/so3.png" alt="" />
                        </div>
                        <div class="details">
                            <h2>
                                ClickDesire
                            </h2>
                            <h3>
                                Special Offers</h3>
                            <p class="title">
                                Buy a Combo of Western Girl Dress at the Price of one</p>
                            <p class="description">
                                Buy Two similar westren Dresses at the price of Single Dress
                            </p>
                            <a href="#" class="read-more-btn">Read More</a>
                        </div>
                    </li>
                    <li>
                        <div class="image">
                            <img src="css/images/so4.png" alt="" />
                        </div>
                        <div class="details">
                            <h2>
                                ClickDesire
                            </h2>
                            <h3>
                                Special Offers</h3>
                            <p class="title">
                                Sale!! Sale!! Sale!!</p>
                            <p class="description">
                                All Casual Wear From just Rs.500</p>
                            <a href="#" class="read-more-btn">Read More</a>
                        </div>
                    </li>
                    <li>
                        <div class="image">
                            <img src="css/images/so5.png" alt="" />
                        </div>
                        <div class="details">
                            <h2>
                                ClickDesire
                            </h2>
                            <h3>
                                Special Offers</h3>
                            <p class="title">
                                Buy a Combo of Mens T-Shirts at the Price of one</p>
                            <p class="description">
                                Buy Two similar T-Shirts at the price of Single T-Shirt
                            </p>
                            <a href="#" class="read-more-btn">Read More</a>
                        </div>
                    </li>
                </ul>
                <div class="nav">
                    <a href="#">1</a> <a href="#">2</a> <a href="#">3</a> <a href="#">4</a> <a href="#">
                        5</a> <a href="#">6</a>
                </div>
            </div>
        </div>
        <!-- End Slider -->
        <!-- Main -->
        <div id="main" class="shell">
            <!-- Sidebar -->
            <div id="sidebar">
                <ul class="categories">
                    <li>
                        <div id='cssmenu'>
                            <h4>
                                Categories</h4>
                            <asp:Repeater ID="repcategory" runat="server" OnItemDataBound="repcategory_ItemDataBound">
                                <HeaderTemplate>
                                    <ul>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:HiddenField ID="hf1" Value='<%# Eval("CategoryID") %>' runat="server" />
                                    <li class="active has-sub"><a href='#'><span>
                                        <%#Eval("CategoryName") %></span></a>
                                        <asp:Repeater ID="repsubcategory" OnItemDataBound="repsubcategory_ItemDataBound"
                                            runat="server">
                                            <HeaderTemplate>
                                                <ul>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:HiddenField ID="hf2" Value='<%# Eval("SubCategoryID") %>' runat="server" />
                                                <li class="has-sub"><a href='#'><span>
                                                    <%#Eval("SubCategoryName") %></span></a>
                                                    <asp:Repeater ID="repsubcategory2" OnItemDataBound="repsubcategory2_ItemDataBound"
                                                        runat="server">
                                                        <HeaderTemplate>
                                                            <ul>
                                                        </HeaderTemplate>
                                                        <ItemTemplate>
                                                            <asp:HiddenField ID="hf3" Value='<%# Eval("SubCategory2ID") %>' runat="server" />
                                                            <li><a href='AnonymousProductSubCategory2.aspx?SubCategory2ID=<%# Eval("SubCategory2ID") %>'>
                                                                <span>
                                                                    <%#Eval("SubCategory2Name") %></span></a> </li>
                                                        </ItemTemplate>
                                                        <FooterTemplate>
                                                            </ul>
                                                        </FooterTemplate>
                                                    </asp:Repeater>
                                                </li>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                </ul></FooterTemplate>
                                        </asp:Repeater>
                                    </li>
                                </ItemTemplate>
                                <FooterTemplate>
                                    </ul></FooterTemplate>
                            </asp:Repeater>
                        </div>
                    </li>
                    <li>
                        <h4>
                            Authors</h4>
                        <asp:Repeater ID="repcompany" runat="server">
                            <HeaderTemplate>
                                <ul>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <li>
                                    <%--  <asp:HyperLink ID="hyperCompany" runat="server"><%#Eval("CompanyName") %></asp:HyperLink>--%>
                                    <a href='AnonymousCompanyProduct.aspx?CompanyID=<%# Eval("CompanyID") %>'><span>
                                        <%#Eval("CompanyName")%></span></a> </li>
                            </ItemTemplate>
                            <FooterTemplate>
                                </ul></FooterTemplate>
                        </asp:Repeater>
                    </li>
                </ul>
            </div>
            <!-- End Sidebar -->
            <!-- Content -->
            <div id="content">
                <!-- Products -->
                <div class="products">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    </asp:ContentPlaceHolder>
                    <!-- End Products -->
                </div>

            <!-- End Content -->
            <div class="cl">
                &nbsp;</div>
        </div>
        <!-- End Main -->
        <!-- Footer -->
        <div id="footer" class="shell">
            <div class="top">
                <div class="cnt">
                    <div class="col about">
                        <h4>
                            About clickDesire.com</h4>
                        <p>
                            It's nice of you to take the time to get to know us better. Here are some things
                            about us that we thought you might like to know.
                            <br />
                            ClickDesire was developed in 2013 as a Project to be submitted in College.We're
                            present across various categories including healthcare and personal products,apparels,
                            shoes – and still counting!
                            <br />
                            Be it our path-breaking services like Cash on Delivery, a 30-day replacement policy,
                            EMI options, free shipping - and of course the great prices that we offer, everything
                            we do revolves around our obsession with providing our customers a memorable online
                            shopping experience. Then there's our dedicated ClickDesire delivery partners who
                            work round the clock to personally make sure the packages reach on time.
                            <br />
                            So it's no surprise that we're a favourite online shopping destination.
                        </p>
                    </div>
                    <div class="col store">
                        <h4>
                            Store</h4>
                        <ul>
                            <li><a href="#">Home</a></li>
                            <li><a href="#">Special Offers</a></li>
                            <li><a href="#">Log In</a></li>
                            <li><a href="#">Account</a></li>
                            <li><a href="#">Basket</a></li>
                            <li><a href="#">Checkout</a></li>
                        </ul>
                    </div>
                    <div class="col" id="newsletter">
                        <h4>
                            Newsletter</h4>
                        <p>
                            Lorem ipsum dolor sit amet consectetur.
                        </p>
                        <form action="" method="post">
                        <input type="text" class="field" value="Your Name" title="Your Name" />
                        <input type="text" class="field" value="Email" title="Email" />
                        <div class="form-buttons">
                            <input type="submit" value="Submit" class="submit-btn" />
                        </div>
                        </form>
                    </div>
                    <div class="cl">
                        &nbsp;</div>
                    <div class="copy">
                        <p>
                            &copy; <a href="#">BestSeller.com</a>. Design by <a href="http://css-free-templates.com/">
                                CSS-FREE-TEMPLATES.COM</a></p>
                    </div>
                </div>
            </div>
        </div>
        <!-- End Footer -->
    </div>
     <div id="myModal" class="reveal-modal">

         <div id=signup>   
                <h1>
                    <b>Signin</b></h1>
                <asp:TextBox ID="txtusername" placeholder="Choose Your UserName" required="" runat="server"
                     ValidationGroup="vg2"></asp:TextBox>
                <asp:RequiredFieldValidator ID="requser" runat="server" ControlToValidate="txtusername"
                    ErrorMessage="Please Enter UserName" ValidationGroup="vg2"></asp:RequiredFieldValidator>
                <asp:TextBox ID="txtpassword" placeholder="Choose your password" required="" runat="server"
                    TextMode="Password" ValidationGroup="vg2"></asp:TextBox>
                <asp:RequiredFieldValidator ID="reqpassword" runat="server" ControlToValidate="txtpassword"
                    ErrorMessage="Please Enter Password" ValidationGroup="vg2"></asp:RequiredFieldValidator>
                <asp:Button ID="Login" runat="server" ValidationGroup="vg2" OnClick="Login_Click"  Text="SignIn" />
                <asp:LinkButton ID="signuplink" runat="server" OnClick="LinkLoginClick" >Register Now</asp:LinkButton>
                <asp:Label ID="lblloginmsg" runat="server" Text=""></asp:Label>
                <!-- End Products -->
          </div>
            <a class="close-reveal-modal">&#215;</a>
        </div>

    </form>
</body>
</html>

以及按钮的点击事件

 protected void LoginClick(object sender, EventArgs e)
    { 
         string userName = txtusername.Text.Trim().ToString();
         LoginInfo login = new DBAction.Login().GetLoginData(userName);
         if (login != null)
         {

                Session["UserName"] = txtusername.Text.Trim().ToString();
                lblloginmsg.Text = "Login In Process";
                Response.Redirect("./client/ClientHome.aspx");
            }
            else if (login == null)
            {
                lblloginmsg.Text="UserName or password is incorrect";
            }
         }


    }

只需给出div id就可以在其母版页上调用div 问题是什么,请帮忙

1 个答案:

答案 0 :(得分:0)

我在刚刚创建的新ASP.NET Web窗体应用程序中尝试过您的代码。代码工作得很好,我也来了按钮代码。你没有粘贴上面的所有代码,所以我把它粘贴在这里,你可以看到代码中是否有任何遗漏。这是我在这里粘贴的,在我的计算机上运行得很好(Visual Studio 2012和.Net 4.5)

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
  <section class="featured">
    <div class="content-wrapper">
        <hgroup class="title">
            <h1><%: Title %>.</h1>
            <h2>Modify this template to jump-start your ASP.NET application.</h2>
        </hgroup>
        <p>
            To learn more about ASP.NET, visit <a href="http://asp.net" title="ASP.NET Website">http://asp.net</a>.
            The page features <mark>videos, tutorials, and samples</mark> to help you get the most from ASP.NET.
            If you have any questions about ASP.NET visit
            <a href="http://forums.asp.net/18.aspx" title="ASP.NET Forum">our forums</a>.
        </p>
    </div>
  </section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <h3>We suggest the following:</h3>
    <div id="myModal" class="reveal-modal">
        <p>  
        <div id="signup">
            <h1>
                <b>Signin</b></h1>
            <asp:TextBox ID="txtusername" placeholder="Choose Your UserName" required="" runat="server"
                onclick="this.value='';" onblur="this.value"></asp:TextBox>
            <asp:RequiredFieldValidator ID="requser" runat="server" ControlToValidate="txtusername"
                ErrorMessage="Please Enter UserName" ValidationGroup="vg1"></asp:RequiredFieldValidator>
            <asp:TextBox ID="txtpassword" placeholder="Choose your password" required="" runat="server"
                TextMode="Password"></asp:TextBox>
            <asp:RequiredFieldValidator ID="reqpassword" runat="server" ControlToValidate="txtpassword"
                ErrorMessage="Please Enter Password" ValidationGroup="vg1"></asp:RequiredFieldValidator>
            <asp:Button ID="Login" runat="server" OnClick="LoginClick" ValidationGroup="vg1" Text="SignIn" /><br />
            <asp:LinkButton ID="signuplink" runat="server" OnClick="LinkLoginClick" >Register Now</asp:LinkButton>
            <asp:Label ID="lblloginmsg" runat="server" Text=""></asp:Label>
            <!-- End Products -->
        </div></p>
        <a class="close-reveal-modal">&#215;</a>
    </div>
</asp:Content>

按钮的代码几乎相同。我的Visual Studio希望它是Public而不是Protected。您也可以尝试进行更改。

public void LoginClick(object sender, EventArgs e)
{
    // ...
}