如何在ScriptManager.RegisterClientScriptBlock中顯示catch錯誤消息? 下面是我的按鈕點擊event.like我們可以通過使用ex.message獲得標籤中的錯誤消息,所以如何使用此警報彈出消息框?如何在ScriptManager.RegisterClientScriptBlock中顯示catch錯誤消息
public void IssueDelete()
{
try
{
//open the db connection if it is closed...
if (connection.State == ConnectionState.Closed)
connection.Open();
int issueId = Convert.ToInt32(ddlComplaintDelete.SelectedValue);
command = new SqlCommand();
command.CommandText = "sp_IssueDelete";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@registrationId", lblUploadRegistrationId.Text);
command.Parameters.AddWithValue("@issueId", issueId);
command.Connection = connection;
command.ExecuteNonQuery();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('Issue Deleted Succesfully');", true);
}
catch (Exception ex)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('Cannot Delete');", true);
}
finally //Close db Connection if it is open....
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
}
protected void btnComplaintDelete_Click(object sender, EventArgs e)
{
IssueDelete();
}
你在哪裏發現C#代碼或JavaScript錯誤? – Adil
沒有收到任何錯誤,但消息框沒有發生變化。 – asma
你有RegisterClientScriptBlock語句的地方嗎? – Adil