0
我使用ASP.NET從代碼隱藏更改過程值?
我想在數據庫工作時從代碼隱藏中向用戶顯示百分比。
我想問題是在這裏,當我從cs percentege調用這個函數工作精美!
protected void btnUpdate_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(5000);
}
但我真正的代碼是連接數據庫並插入300 - 1000行! 它工作時服務器光標圖標變爲忙圖標,所以它凍結,我不能設置我的百分比值。
plz幫助...
我有一個Web服務:
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按鈕的onclick:
<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動作代碼 保護無效btnAction_Click(對象發件人,EventArgs的){
...
...
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);
...
...
}
thx我在嘗試 – Mennan
我怎麼能打電話給這個PageAsyncTask?它只有一個電話我無法想象它。我想每秒鐘打電話給我,我該怎麼做? – Mennan
您不希望每秒鐘只調用一次PageAsyncTask。在我的答案中查看添加的註釋。 –