ASCX页面按钮单击不激发服务器端

时间:2015-12-09 22:07:03

标签: c# .net

我有一个Master页面,它在名为Employee的aspx页面中继承。以下是aspx页面的相关代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Employee.aspx.cs" Inherits="ICA_Nagerbajar.Employee" MasterPageFile="~/Master.Master" %>
<%@ Register TagPrefix="e" TagName="Entry" Src="~/EmployeeView/EmployeeEntry.ascx" %>
<%@ Register TagPrefix="v" TagName="ViewEdit" Src="~/EmployeeView/EmployeeViewEdit.ascx" %>
<asp:Content ID="ContentBody" ContentPlaceHolderID="MasterBodyPlaceHolder" runat="server">

    <div class="tabbable">
        <ul class="tabs">
            <li><a href="#tab1">Entry</a></li>
            <li><a href="#tab2">View/Edit</a></li>
        </ul>
        <div class="tabcontent">
            <asp:HiddenField ID="TabData" runat="server" />
            <div id="tab1" class="tab" style="display:inline-block">
                <e:Entry ID="EmpEntry" runat="server" />
            </div>

            <div id="tab2" class="tab" style="display:inline-block">
                <v:ViewEdit ID="EmpViewEdit" runat="server" />
            </div>
        </div>
    </div>

</asp:Content>

现在在其中一个ascx页面(EmployeeEntry.ascx)按钮工作正常。但在另一个(EmployeeViewEdit.ascx)它不工作。以下是EmployeeViewEdit.ascx的相关代码

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EmployeeViewEdit.ascx.cs" Inherits="ICA_Nagerbajar.EmployeeView.EmployeeViewEdit" %>
<div class="boxed">
   <input id="TextBoxUserNameSearch" runat="server" class="textstyle" placeholder="Name" type="text"/>
   <asp:Button ID="ButtonSearch" runat="server" Text="Search" class="btnsubmitstyle" OnClick="ButtonSearch_Click"/>
</div>  

Server Side Code

  #region Search Button Click
        protected void ButtonSearch_Click(object sender, EventArgs e)
        {
            string userName = TextBoxUserNameSearch.Value.Trim();
            GetEmployee(userName + "%");
        }
  #endregion

我做的观察很少

  1. 如果我用链接按钮取代按钮,其工作正常

  2. 没有Button在这个ascx中工作,虽然它在另一个ascx中工作

  3. 如果我在父页面中注释掉第一次调用ascx,那么该按钮正在工作,即<e:Entry ID="EmpEntry" runat="server" />

1 个答案:

答案 0 :(得分:0)

正如@JBKing所建议的那样,将Button的UseSubmitBehaviour属性设置为&#34; false&#34;解决了我的问题

<asp:Button ID="ButtonSearch" runat="server" Text="Search" CssClass="btnsubmitstyle" OnClick="ButtonSearch_Click" UseSubmitBehaviour="false"/>