[英]How to perform javascript inside C# event
我在一個事件內,並且在此事件內,我想讓一個javascript警報向用戶顯示一條消息。 但是我似乎無法使它起作用。
protected void dgvStaff_Deleting(object sender, Infragistics.Web.UI.GridControls.RowDeletingEventArgs e)
{
// Code stub
object test = e.Row.Items[0].Text;
//ScriptManager.RegisterStartupScript(this, this.GetType(), "alertbox", "ShowPopup('Select a row to rate');", true);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertbox", "ShowPopup('Select a row to rate');", true);
if (objGatewayFunctions.CheckStaffAssignment(e.Row.Items[0].Text.ToString(), ConfigurationManager.AppSettings.Get("Connection").ToString()) == true)
{
}
}
知道我在這里做錯了嗎?
您不能這樣做-C#和JavaScript在不同的計算機上運行,並且您不能在函數中間在它們之間跳轉。
通常,您會延遲錯誤/警告,直到頁面呈現為止。 為了改善用戶體驗,還應嘗試在返回服務器之前進行錯誤檢查(除了服務器端檢查之外)。
您必須等待服務器執行完成,然后才能看到正在執行的客戶端執行。
用這個
Response.Write("<script type='text/javascript'>alert('Hello World');</script>");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.