我使用 ASP.NET
我想在数据库工作时从代码隐藏向用户显示百分比。
我认为问题就在这里,当我从 cs percentege 调用这个函数时,工作正常!
protected void btnUpdate_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(5000);
}
但我真正的代码是连接数据库并插入 300 - 1000 行!当它工作时,服务器光标图标变为忙碌图标,所以它冻结了,我无法设置我的百分比值。
请帮忙...
我有一个网络服务:
public double CommittedCount = 0;
[WebMethod]
public string ShowPercentage()
{
return ((CommittedCount / FinishCount) * 100 ).ToString();
}
[WebMethod]
public void SetCommittedCount(double committedCount)
{
CommittedCount = committedCount;
}
public double FinishCount
{
get
{
if(Glob.ExcelDataSet.Tables[0].Rows.Count > 0)
return Glob.ExcelDataSet.Tables[0].Rows.Count;
return 1;
}
}
我有一个ajaxcall函数:
function updateProgress() {
$.ajax({
type: "POST",
url: '<%=ResolveUrl("~/processCalculator.asmx/ShowPercentage") %>',
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (msg) {
// TODO: revert the line below in your actual code
//$("#progressbar").progressbar("option", "value", msg.d);
$(".percentage").text(msg.d);
if (msg.d < 100) {
setTimeout(updateProgress, 100);
}
}
});
}
我在点击时调用了 updateProgress 按钮:
<asp:Button Text="Sorgula" ID="btnAction" class="button_action" OnClick="Action_Click" Width="80px" runat="server" />
$(".button_action").click(function () {
var action_ = $(this).attr("value");
var ExcelRowCount = $('#<%=ExcelActionsIsAvaibleRowCount.ClientID %>').val();
if (ExcelRowCount != "") {
if (confirm(ExcelRowCount + " kayıt için [" + action_ + "] aksiyonu gerçekleştirilecek?")) {
setTimeout(updateProgress, 100);
return true;
}
else
{
return false;
}
}
});
我的 Cs 操作代码受保护 void btnAction_Click(object sender, EventArgs e) {
...
...
for (int rowIndex = 1; rowIndex < Glob.ExcelDataSet.Tables[0].Rows.Count; rowIndex++)
{
...
...
aksiyon_sonucu_ = action.InsertRow(
Glob.ExcelDataSet.Tables[0].Rows[rowIndex], DegistirilebilirKolonlar, true);
// my persentage
processCalculater pCal = new processCalculater();
pCal.SetCommittedCount(rowIndex);
...
...
}