我正在使用 Page.ClientScript.RegisterStartupScript(); 在 asp.net C# 中显示一条消息
如果我写下面的代码,那么它的工作
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowMessage", string.Format("<script type='text/javascript'>alert('{0}')</script>", "Record Saved"));
Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", string.Format("<script type='text/javascript'>alert('{0}')</script>", ex.Message.ToString()));
但如果我写
string Result = objChap.Insert();
Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", string.Format("<script type='text/javascript'>alert('{0}')</script>", Result));
然后它不工作意味着消息框不显示
我的完整代码是
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
objChap.FK_SemesterID = Convert.ToDecimal(drplstSem.SelectedValue);
objChap.FK_SubjectID = Convert.ToDecimal(drplstSub.SelectedValue);
objChap.ChapterName= txtChap.Text;
objChap.ChapterSName = txtChapShortName.Text;
objChap.Remarks = txtRemarks.Text;
objChap.Dta_User = Global.Dta_User;
objChap.Dta_Users = Global.Dta_User;
string Result = objChap.Insert();
if (Result == "1")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowMessage", string.Format("<script type='text/javascript'>alert('{0}')</script>", "Record Saved"));
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Error1", string.Format("<script type='text/javascript'>alert('{0}')</script>", Result));
}
}
catch (Exception ex)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", string.Format("<script type='text/javascript'>alert('{0}')</script>", ex.Message.ToString()));
}
}