javascript通过代码确认

时间:2013-08-21 10:04:44

标签: c# javascript jquery asp.net

以下查询位于文本框中

SELECT  [Brewery], [CP CS]   FROM [Vw_QueryBuilder_27QueryBuilder1]  

这两个字段在某些报告中使用

现在,如果有人删除上述任何一栏,则会要求确认删除所有相关报告

我坚持确认

我尝试过

  ScriptManager.RegisterStartupScript(Page, typeof(Page), "somekey", "Confirm()", true);
                   // Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "Confirm()", true);
                  //  Response.Write("<script>javascript:Confirm();</script>");
                    string confirmValue = CnfHide.Value.Trim();
                    if (confirmValue == "1")

javascript是

 function Confirm() {

        if (confirm("Some columns are being used in other reports, removing those columns from query builder will lead to remove all related reports. Dou you want to proceed?")) {
            $("#ContentPlaceHolder1_CnfHide").val("1");
        } else {
            $("#ContentPlaceHolder1_CnfHide").val("0");
        }

    }

确认窗口正在出现,但它没有存储值1或0或停在该点,它只是传递函数后面的所有行

3 个答案:

答案 0 :(得分:0)

您可以使用PopUpextender并在java脚本中开发确认 推荐帖子 http://www.codeproject.com/Questions/185470/Javascript-confirm-message-from-code-behind

或者尝试使用in.cs代码

string msg1;         msg1 =“确认('你确定要删除Madhuri的数据......!');”;         if(!ClientScript.IsStartupScriptRegistered(“error”))         {             RegisterStartupScript(“error”,msg1);         }

答案 1 :(得分:0)

要在客户端使用confirm(),您确实需要从函数返回一个值。 e.g。

function Confirm() {

    var result = confirm("Some columns are being used in other reports, removing those columns from query builder will lead to remove all related reports. Dou you want to proceed?");

    if (result) {
        $("#ContentPlaceHolder1_CnfHide").val("1");
    } else {
        $("#ContentPlaceHolder1_CnfHide").val("0");
    }

    return result;

}

如果你没有从函数中返回true或false,那么它将始终只是“传递函数后面的代码中的所有行”。

答案 2 :(得分:0)

有几种方法可以解决此问题。

  1. 您的选择器没有返回元素

    Confirm功能更改为:

    function Confirm() {
      console.log($("#ContentPlaceHolder1_CnfHide").length);
    }
    

    如果返回0,请通过查看浏览器中页面的来源,检查生成的CnfHide标记,并检查该ID是否与您的选择器匹配。

    当您使用ASP.NET时,您可能希望使用这个方便的函数,该函数将返回ID以您指定的值结尾的元素。将元素包装在另一个服务器端控件中时,这很方便。

    $.extend({
      clientID: function (id) {
        return $("[id$='" + id + "']");
      }
    });
    

    用法:$.clientID('CnfHide').val("0");

  2. 脚本未发送到客户端

    您可以通过在浏览器中查看页面来源并搜索if (confirm("Some columns are being use

    之类的内容来确认这一点

    如果您在页面上找不到此字符串,则需要找出ScriptManager类未将此数据发送给客户端的原因。

    以下是一些可能有助于您识别服务器端问题的资源

    Startup script registered with ScriptManager.RegisterStartupScript is not rendered to page

    Client method called by ScriptManager.RegisterStartupScript not firing

    Client side script won't execute with ScriptManager

相关问题