我正在使用Page.ClientScript.RegisterStartupScript();顯示在asp.net C#在asp.net c#中不顯示消息框使用Page.ClientScript.RegisterStartupScript()
消息如果我寫了下面的代碼,然後它的工作
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()));
}
}
我檢查你的腳本 - 它的工作原理 – Alex 2013-02-21 10:19:13
@voo但在我身邊它不起作用 – Pritesh 2013-02-21 10:29:37
也許這個字符串包含引號,打破了腳本。你能調試,看看'Result'的價值嗎? – 2013-02-21 10:43:15