开发者

i have many div in my aspx page. how to update the content of a particular div?

开发者 https://www.devze.com 2022-12-30 07:16 出处:网络
I开发者_JAVA百科 have many div in my aspx page. how to update the content of a particular div? It should update every one minute time interval..

I开发者_JAVA百科 have many div in my aspx page. how to update the content of a particular div?

It should update every one minute time interval.. with out reloading entire page..


Certainly can do as Raj has pointed out but requires you to send back HTML code that is only thats needed. If you've got it in a ASPX page, it'll send the full HTML which is not that you want.

If you've done it with with MS-AJAX / UpdatePanel, you can use jQuery or a JavaScript timer to trigger a hidden button which will cause any server side code to update.

Please let me know if you want some examples

EDIT - new code sample

This is via jQuery, in the HTML HEAD

<style>
.hidden {visibility: none;}
</style>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
    // this part will tell the MS AJAX framework to call SetupTrigger when the AJAX call back is done
    if (typeof Sys != "undefined") {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(SetupTrigger);
    }
    SetupTrigger()
}
</script> 

Then in your HTML body

<script language="javascript">
function SetupTrigger() {
    var refresh = 60 * 1000;
    window.setTimeout(function() {
        TriggerUpdate();
    }, refresh);
}
function TriggerUpdate() {
   //simulates the button click
   $("#<%=btnUpdatePanel.ClientID%>").click();
}
</script>

<asp:UpdatePanel runat="server" ID="upPanel" UpdateMode="Conditional" ChildrenAsTriggers="true">
    <ContentTemplate>
            <asp:Button runat="server" ID="btnUpdatePanel" OnClick="ServerSideFunctionToCall" CssClass="hidden" />
    <!-- content to update -->
    </ContentTemplate>
</asp:UpdatePanel>
0

精彩评论

暂无评论...
验证码 换一张
取 消