这只是我想要实现的示例代码,而且无法通过Javascript执行。
使用Updatepanel并尝试更新进度条,它在功能执行时显示进度
但是在执行此操作时,updatepanel会在刷新时从零开始
(这不是平滑的连续转换,而是从零开始并且每次发生timer-tick事件时都到达指定点)
ASPX
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Timer runat="server" ID="Timer1" Interval="1000" Enabled="False"
ontick="Timer1_Tick" />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<br />
<br />
<div id="div3" runat="server" class="progress progress-danger progress-striped progress progress_sm active " style="width: 100%;">
<div id="e3" class="bar" runat="server" role="progressbar">
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
的JavaScript
var percentage;
function updateProgress2(percentage) {
var $bar1 = $("#e3");
//var $bar1 = $('.bar');
var pp = percentage + "%";
$bar1.width(pp);
$bar1.text(pp + "%");
}
C#
static int count2, i;
protected void Button1_Click(object sender, EventArgs e)
{
i=0;
count2=20;
Button1.Enabled = false;
Timer1.Enabled = true;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "lol", "updateProgress2('" + count2 + "')", true);
i++;
count2 += 10;
if (count2 == 90)
{
Timer1.Enabled = false;
Button1.Enabled = true;
}
}
答案 0 :(得分:0)
我希望看到你的'count2'属性。
我可以在会话中使用这个'count2'属性。
此代码正常工作。
private int count2
{
get
{
if (Session["count2"] == null)
Session["count2"] = 0;
return int.Parse(Session["count2"].ToString());
}
set
{
Session["count2"] = value;
}
}