how to trigger updatepanel within a javascript function

后端 未结 2 1310
梦如初夏
梦如初夏 2021-02-05 18:24

i have an updatepanel in my asp.net web page. I want to trigger the updatepanel within a javascript function insead of triggering with a button.
In order to do that, i used

相关标签:
2条回答
  • 2021-02-05 18:40

    Just create a javascript function and execute the generated postback event:

    <%=ClientScript.GetPostBackEventReference(myUpdatePanel, "")%>
    

    The above statement is put on your aspx page, and it references the exact same code generated from the server to cause a postback for your panel. You can use it by putting it inside a function on the client side:

    function fncUpdatePanel () {
        <%=ClientScript.GetPostBackEventReference(myUpdatePanel, "")%>;
    }
    

    Then you can attach that function to any event on your page (even a mouseover event). This example uses a server side to attach the event:

    myUpdatePanel.attributes('onmouseover', 'fncUpdatePanel()')
    
    0 讨论(0)
  • 2021-02-05 19:00

    I think if you put a hidden button inside the update panel and you can use the javascript to fire the click of this button, it will do what you want.

    <script type="text/javascript">
            function Update_UpdatePaanel() {
                document.getElementById('<%= YourButton.ClientID %>').click()
            }
        </script>
    

    The button MUST be inside a hidden div and DON'T set visibile="false" because if you set it to false, the control will not render and the javascript will produce errors.

    <div style="display:none">
            <asp:Button ID="YourButton" runat="server" />
        </div>
    
    0 讨论(0)
提交回复
热议问题