LinkBut​​ton事件未通过引导数据切换触发

时间:2017-04-04 08:52:53

标签: asp.net events postback linkbutton

我的asp页面中有一个菜单,由链接按钮组成。我正在使用div容器和unorder列表。每个列表项都是一个链接按钮。我的问题是,当我点击链接按钮时,它不会回发。

我的asp代码:

    <%@ Page Language="C#" MasterPageFile="~/Companies.master" AutoEventWireup="true" CodeBehind="Shareholder.aspx.cs" Inherits="GAD.Shareholder" Title="Untitled Page" %>
<%@ Register Src="~/Controls/ShareholderListControl.ascx" TagPrefix="gad" TagName="ShareholderListControl" %>
<%@ Register Src="~/Controls/ShareholderEditControl.ascx" TagPrefix="gad" TagName="ShareholderEditControl" %>

<%@ Register Src="~/Controls/CapitalSubscriptionListControl.ascx" TagPrefix="gad" TagName="CapitalSubscriptionListControl" %>
<%@ Register Src="~/Controls/CapitalSubscriptionEditControl.ascx" TagPrefix="gad" TagName="CapitalSubscriptionEditControl" %>

<%@ Register Src="~/Controls/ShareholderCollectListControl.ascx" TagPrefix="gad" TagName="ShareholderCollectListControl" %>
<%@ Register Src="~/Controls/ShareholderCollectEditControl.ascx" TagPrefix="gad" TagName="ShareholderCollectEditControl" %>

<%@ Register Src="~/Controls/ShareholderExpenditureListControl.ascx" TagPrefix="gad" TagName="ShareholderExpenditureListControl" %>
<%@ Register Src="~/Controls/ShareholderExpenditureEditControl.ascx" TagPrefix="gad" TagName="ShareholderExpenditureEditControl" %>

<%@ Register Src="~/Controls/ShareholderPayoutListControl.ascx" TagPrefix="gad" TagName="ShareholderPayoutListControl" %>
<%@ Register Src="~/Controls/ShareholderPayoutEditControl.ascx" TagPrefix="gad" TagName="ShareholderPayoutEditControl" %>

<%@ Register Src="~/Controls/DocumentListControl.ascx" TagPrefix="gad" TagName="DocumentListControl" %>
<%@ Register Src="~/Controls/DocumentEditControl.ascx" TagPrefix="gad" TagName="DocumentEditControl" %>

<%@ Register Src="~/Controls/AlertListControl.ascx" TagPrefix="gad" TagName="AlertListControl" %>
<%@ Register Src="~/Controls/AlertEditControl.ascx" TagPrefix="gad" TagName="AlertEditControl" %>

<%@ Register Src="~/Controls/LetterListControl.ascx" TagPrefix="gad" TagName="LetterListControl" %>

<%@ Register Src="~/Controls/ShareListControl.ascx" TagPrefix="gad" TagName="ShareListControl" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderCompany" runat="server">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">



<div id="exTab" class="container" runat="server">   
    <ul id="myTab"  class="nav nav-pills" runat="server">
        <li id="Li1" class="active" runat="server">
    <asp:LinkButton ID="TabLink1" data-toggle="tab" CssClass="alink" runat="server" OnClick="ChangeView">ACTIONARI/ASOCIATI</asp:LinkButton>
        </li>
        <li id="Li2" runat="server">
    <asp:LinkButton ID="TabLink2" data-toggle="tab" CssClass="alink" runat="server" OnClick="ChangeView">DOCUMENTE</asp:LinkButton>
        </li>
        <li><a href="#3b" data-toggle="tab">Applying clearfix</a>
        </li>
    <li><a href="#4a" data-toggle="tab">Background color</a>
        </li>
    </ul>

  </div>
<asp:HiddenField ID="hdnTab" runat="server" Value="" />
<script type="text/javascript">
    $(document).ready(function () {
        if ($("#hdnTab").val() != '')
            $('#myTab li').removeClass("active");
        $('#myTab a[id="' + $("#hdnTab").val() + '"]').parent().addClass("active");
        $(".alink").click(function () {
            $("#hdnTab").val($(this).attr("id"))
            __doPostBack($(this).attr("id"), "");
        });
    });


</script>


    <div class="container" >
    <asp:Panel ID="PanelMain" runat="server">
        <asp:MultiView ID="MultiViewMain" runat="server" ActiveViewIndex="0">
            <asp:View ID="ViewList" runat="server">
                <gad:ShareholderListControl ID="List" Tag="Shareholder" runat="server"></gad:ShareholderListControl>
            </asp:View>
            <asp:View ID="ViewEdit" runat="server">
                <gad:ShareholderEditControl ID="Edit" Tag="Shareholder" runat="server"></gad:ShareholderEditControl>

           </asp:View>


             <asp:View ID="ViewList_CapitalSubscription" runat="server">
                        <gad:CapitalSubscriptionListControl ID="CapitalSubscriptionListControl" Tag="CapitalSubscription" runat="server" />
                    </asp:View>
             <asp:View ID="ViewEdit_CapitalSubscription" runat="server">
                        <gad:CapitalSubscriptionEditControl ID="CapitalSubscriptionEditControl" Tag="CapitalSubscription" runat="server" />
                   </asp:View>


               <asp:View ID="ViewList_Document" runat="server">
                        <gad:DocumentListControl ID="DocumentListControl" Tag="Document" runat="server" />
                    </asp:View>
               <asp:View ID="ViewEdit_Document" runat="server">
                        <gad:DocumentEditControl ID="DocumentEditControl" Tag="Document" runat="server" />
                   </asp:View>


        </asp:MultiView>

    </asp:Panel>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</asp:Content>

代码背后:

public void ChangeView(object sender, EventArgs e) {
            LinkButton lnkButton = sender as LinkButton;
            switch (lnkButton.Text) {
                case "ACTIONARI/ASOCIATI": MultiViewMain.SetActiveView(ViewList);
                    break;
                case "DOCUMENTE": MultiViewMain.SetActiveView(ViewList_Document);
                    break;
                default:
                    break;
            }
        }

在调试模式下,我放了断点但我的应用程序没有进入我的事件函数......

1 个答案:

答案 0 :(得分:0)

如果你真的想要链接按钮发回来,你将无法获得&#39; nav&#39;的实际功能。功能。肯定会回复。在该场景中,使用以下代码

引入隐藏字段以捕获您点击的链接

<asp:HiddenField ID="hdnTab" runat="server" Value="" />

然后使用此脚本发回服务器代码

  <script>
    $(document).ready(function () {
        if ($("#hdnTab").val() != '')
            $('#myTab li').removeClass("active");
        $('#myTab a[id="' + $("#hdnTab").val() + '"]').parent().addClass("active");
        $(".alink").click(function () {
            $("#hdnTab").val($(this).attr("id"))
            __doPostBack($(this).attr("id"), "");
        });
    });
</script>

整个HTML

<%@ Register Src="~/Control/test.ascx" TagPrefix="uc1" TagName="test" %>
<%@ Register Src="~/Control/Tab2.ascx" TagPrefix="uc1" TagName="Tab2" %>

<div id="exTab" class="container" runat="server">   
<ul id="myTab"  class="nav nav-pills" runat="server">
    <li id="Li1" class="active" runat="server">
<asp:LinkButton ID="TabLink1" data-toggle="tab" CssClass="alink" runat="server" OnClick="ChangeView">ACTIONARI/ASOCIATI</asp:LinkButton>
    </li>
    <li id="Li2" runat="server">
<asp:LinkButton ID="TabLink2" data-toggle="tab" CssClass="alink" runat="server" OnClick="ChangeView">DOCUMENTE</asp:LinkButton>
    </li>
    <li><a href="#3b" data-toggle="tab">Applying clearfix</a>
    </li>
<li><a href="#4a" data-toggle="tab">Background color</a>
    </li>
</ul> </div><asp:HiddenField ID="hdnTab" runat="server" Value="" /><div class="container" >
<asp:Panel ID="PanelMain" runat="server">
    <asp:MultiView ID="MultiViewMain" runat="server" ActiveViewIndex="0">
        <asp:View ID="ViewList" runat="server">
             <uc1:test runat="server" id="test" />
        </asp:View>
        <asp:View ID="ViewEdit" runat="server">
            View Edit
       </asp:View>


         <asp:View ID="ViewList_CapitalSubscription" runat="server">
             ViewList_CapitalSubscription
                </asp:View>
         <asp:View ID="ViewEdit_CapitalSubscription" runat="server">
             ViewEdit_CapitalSubscription
               </asp:View>


           <asp:View ID="ViewList_Document" runat="server">
               ViewList_Document
                </asp:View>
           <asp:View ID="ViewEdit_Document" runat="server">
               <uc1:Tab2 runat="server" id="Tab2" />
               </asp:View>


    </asp:MultiView>

</asp:Panel>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>