我的 aspx 页面中有很多 div 。如何更新特定div的内容?

发布于 2024-09-01 17:08:21 字数 74 浏览 0 评论 0原文

我的 aspx 页面中有很多 div。如何更新特定div的内容?

它应该每隔一分钟更新一次。 无需重新加载整个页面..

I 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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的笑 2024-09-08 17:08:21

当然可以像 Raj 指出的那样,但要求您发回仅需要的 HTML 代码。如果您将其放在 ASPX 页面中,它将发送您不想要的完整 HTML。

如果您使用 MS-AJAX / UpdatePanel 完成此操作,则可以使用 jQuery 或 JavaScript 计时器来触发隐藏按钮,这将导致任何服务器端代码更新。

如果您想要一些示例,请告诉我

编辑 - 新代码示例

这是通过 jQuery 在 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> 

然后在 HTML 正文中

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文