2

updatepanelを使用するaspxページがあります

ボタンクライアントのクリックよりもページの中央に配置した関数を呼び出すことができません。

このようなコードは機能しません

ケース 1:

<%--some html--%>
<asp:Button ID="btnBotton" runat="server" OnClientClick="return callfunction();" Text="Submit"/>
    <asp:UpdatePanel runat="server">
        <ContentTemplate>
        <%--some content here--%>
        </ContentTemplate>
        <Triggers>
            <%--async trigger --%>
        </Triggers>
    </asp:UpdatePanel>
    <script type="text/javascript">
        function callfunction() {//function placed at the middle of page
            alert('hello');
        }
    </script>
    <%--some html again--%>
</asp:Content>

そして、関数を呼び出すよりもページの最後に関数を配置した場合

ケース 2:

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
    <%--some html--%>
<asp:Button ID="Button1" runat="server" OnClientClick="return callfunction();" Text="Submit"/>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <%--some content here--%>
        </ContentTemplate>
        <Triggers>
            <%--async trigger --%>
        </Triggers>
    </asp:UpdatePanel>
    <%--some html again--%>


    <script type="text/javascript">
        function callfunction() {//function placed at the middle of page
            alert('hello');
        }
    </script>
</asp:Content>

ケース1の問題は何ですか?関数を呼び出せない理由

4

2 に答える 2

0

Updatepanel により、ページのコントロール ツリーが完全に再インスタンス化され、すべてのコントロールがそのライフ サイクル イベントを通じて実行されます。JQuery と WebForms は、通常うまく機能しません。ここでネストに問題があると思いますが、ページ全体を見ないとわかりません。

于 2013-06-22T06:51:33.203 に答える