我想创建一个代表进度条的用户控件。
ASCX:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ProgressBar.ascx.cs" Inherits="A2Controls.Controls.ProgressBar" %>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<%# this.Value %>" aria-valuemin="0" aria-valuemax="100" style="width: <%# this.Value %>%">
<span class="sr-only"><%# this.Value %> Complete</span>
</div>
</div>
代码背后:
public partial class ProgressBar : System.Web.UI.UserControl
{
public int Value { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
}
}
ASPX:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Timer runat="server" ID="clock" OnTick="clock_Tick" Interval="1000" Enabled="true"></asp:Timer>
<uc1:ProgressBar runat="server" ID="ProgressBar" />
</ContentTemplate>
<Triggers >
<asp:AsyncPostBackTrigger ControlID="clock" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
代码背后:
protected void clock_Tick(object sender, EventArgs e)
{
this.ProgressBar.Value++;
}
问题是每次调用tick函数时,updatepanel都会刷新并重新加载整个usercontrol(调用我的意思是构造函数)!我试图将updatepanel逻辑放在usercontrol中,但没有区别。
如何阻止usercontrol再次重新实例化?