我正在使用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