在asyncpostbacktrigger之后不调用Javascript函数

时间:2014-08-06 23:11:52

标签: javascript asp.net triggers updatepanel

我正在使用javascript为我的listview实现双滚动条。当我将asyncpostbacktrigger更改为postbacktrigger按钮单击时,双滚动条显示正常,它通过javascript。但是,每次我使用asyncpostbacktrigger时,它都会在单击按钮后返回到javascript。 有办法解决这个问题吗?

<script type="text/javascript">
    function DoubleScroll(element1) {
        var element = document.getElementById(element1);
        if (!element) return;
        var scrollbar = document.createElement('div');
        scrollbar.appendChild(document.createElement('div'));
        scrollbar.style.overflow = 'auto';
        scrollbar.style.overflowY = 'hidden';

        scrollbar.firstChild.style.width = element.scrollWidth + 'px';
        scrollbar.firstChild.style.paddingTop = '0px';
        scrollbar.firstChild.appendChild(document.createTextNode('\xA0'));
        scrollbar.onscroll = function () {
            element.scrollLeft = scrollbar.scrollLeft;
        };
        element.onscroll = function () {
            scrollbar.scrollLeft = element.scrollLeft;
        };
        element.parentNode.insertBefore(scrollbar, element);
    }

    $(document).ready(function () {
        DoubleScroll('doublescroll');

    })


</script>

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="DropDownList1" />
            <asp:AsyncPostBackTrigger ControlID="Button1" />
            <asp:AsyncPostBackTrigger ControlID="CloneButton" />
        </Triggers>
        <ContentTemplate>
            <div style="text-align: center;">
                <asp:Button ID="CloneButton" runat="server" Text="Clone Report Period" OnClick="CloneButton_Click" />
            </div>
            <div  style="text-align: center; position: absolute; margin-left: auto; margin-right: auto; left: 0; right: 0">
                <b>Program Name</b>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Program" DataValueField="ProgramID">
                </asp:DropDownList>
                &nbsp &nbsp
                <b>Report Period</b>
                <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource3" DataTextField="ReportLabel" DataValueField="DataCollectionPeriodID" Height="21px" Width="172px">
                </asp:DropDownList>
                <asp:Button ID="Button1" runat="server" Height="30px" OnClick="Button1_Click" Text="Search" />
            </div>
   Omitted  
 </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdateProgress ID="updateProgress" runat="server">
        <ProgressTemplate>
            <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: transparent; opacity: 0.7;">
                <asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="~/images/ajax-loader.gif" AlternateText="Loading ..." ToolTip="Loading ..." Style="padding: 10px; position: fixed; top: 45%; left: 50%;" />
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>

1 个答案:

答案 0 :(得分:1)

尝试将您的代码放在客户端pageLoad函数中,而不是$(document).ready(function () {

MSDN上的这篇文章解释了客户端生命周期,可能有一些用处: - http://msdn.microsoft.com/en-us/library/vstudio/bb386417(v=vs.100).aspx