我在主页中添加了可视化 webpart。任何人都可以为我提供 java 脚本以每 2 分钟刷新一次此 Webpart。
谢谢你的时间。
问候,桑迪
我在主页中添加了可视化 webpart。任何人都可以为我提供 java 脚本以每 2 分钟刷新一次此 Webpart。
谢谢你的时间。
问候,桑迪
我相信你可以在没有额外的 JavaScript 的情况下实现这一点。如果您在 Web 部件中构建计时(使用计时器)会怎样?然后,您可以公开允许最终用户调整刷新间隔的 Web 部件属性。如果您不需要调整刷新间隔,那么您不需要公开该属性。希望这会有所帮助。
SAMPLE 请点击此链接了解如何在 Visual Web Parts 中使用 ajax。然后执行以下操作
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server" Height="177px" Width="269px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="10000"
onprerender="Timer1_PreRender" ontick="Timer1_Tick">
</asp:Timer>
</div>
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace vwpTestAjaxRefresh.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
protected void Timer1_Tick(object sender, EventArgs e)
{
string currenttime = DateTime.Now.ToString("MM/dd/yy H:mm:ss zzz");
ListBox1.Items.Add("Hello World at " + currenttime);
}
}
}
希望这可以帮助。