JS Alert无法使用C#背后的代码 [英] JS Alert not working from code behind C#

查看:83
本文介绍了JS Alert无法使用C#背后的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string Result=rptColumnBAL.CheckDuplicateColumnsBAL(calcDetail);
           if (Result == calcDetail.DisplayColumnName)
           {
               Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script language='javascript' type='text/javascript'>alert('The column name you have chosen is already in use. Please enter a different name')</script>");
           }

           else if (Result == "")
           {
               Session["CalcFormula"] = calcDetail.calculationFormula;
               Session["DisplayColumnName"] = calcDetail.DisplayColumnName;
               Session["UseDividendIfZero"] = (cbDividend.Checked == true ? true : false);
               Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseWin", "<script language='javascript'>close();</script>");
           }
          else
           {

               Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script language='javascript' type='text/javascript'>alert('The formula you created already exists under the column name:'" + Result + ")</script>");
           }

推荐答案

试试这个,给你的脚本提供唯一的密钥,让框架将它包装在脚本标签中。< br $>


Try this, give your scripts unique keys and let the framework wrap it in script tags for you.

string Result=rptColumnBAL.CheckDuplicateColumnsBAL(calcDetail);
           if (Result == calcDetail.DisplayColumnName)
           {
               Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alertInvalidColName", "alert('The column name you have chosen is already in use. Please enter a different name');", true);
           }
 
           else if (Result == "")
           {
               Session["CalcFormula"] = calcDetail.calculationFormula;
               Session["DisplayColumnName"] = calcDetail.DisplayColumnName;
               Session["UseDividendIfZero"] = (cbDividend.Checked == true ? true : false);
               Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseWin", "close();", true);
           }
          else
           {
 
               Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alertInvalidFormula", "alert('The formula you created already exists under the column name: " + Result + "');", true);
           };





此外,你在整个地方都有单引号,因此你的脚本可能会被呈现,但只会导致错误当它运行时。



Also you had single quotes all over the place so chances are your script was being rendered but just causing errors when it ran.


这篇关于JS Alert无法使用C#背后的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆