2

following query is in a textbox

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

these two fields are using in some reports

now if some one remove any of the above column , then it will ask for confirmation to delete all related reports

I am stuck with confirmation

i Have tried like

  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 is

 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");
        }

    }

confirm window is appearing but its not storing value 1 or 0 or stop at that point, it just passed all lines in code behind function

Peter
  • 47,963
  • 46
  • 132
  • 181
M Akela
  • 249
  • 5
  • 21
  • When you debug, can you see the `CnfHide` value being changed? Also, can you see any error on the console? – emerson.marini Aug 21 '13 at 10:08
  • no error is there, it just passed through, then after i am able to see confirm popup – M Akela Aug 21 '13 at 10:09
  • But after you respond to the confirmation dialog, can you see the control getting the returned value? I mean, using FF Firebug would make it easier here (inspect element). – emerson.marini Aug 21 '13 at 10:11
  • I don't know c# but the javascript code seems to use jQuery and in jquery you can only use .val() for inputs elements, use .html() instead or .text() for other elements – jvverde Aug 21 '13 at 10:11
  • What is the value of $("#ContentPlaceHolder1_CnfHide").length; when `Confirm` is called? – Zeb Rawnsley Aug 21 '13 at 10:14
  • when i debug the code, its just passed all lines , then confirm window is appearing – M Akela Aug 21 '13 at 10:21
  • all code lines passed then confirm window is appearing and then after its storing 1 or 0 in cnfhid , – M Akela Aug 21 '13 at 10:30

3 Answers3

0

You can use of PopUpextender and develop an confirm like in java script refer post http://www.codeproject.com/Questions/185470/Javascript-confirm-message-from-code-behind

Or try like this in.cs code

string msg1; msg1 = "confirm('are You sure you want to delete Madhuri s data ...!');"; if (!ClientScript.IsStartupScriptRegistered("error")) { RegisterStartupScript("error", msg1); }

Ramakrishna.p
  • 1,159
  • 12
  • 31
0

To use confirm() on the client side you really need to return a value from the function. 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;

}

If you do not return either true or false from the function, then it will always just "passed all lines in code behind function".

Tim B James
  • 20,084
  • 4
  • 73
  • 103
  • i am storing value in a hidden field and then checking it – M Akela Aug 21 '13 at 10:20
  • @pavezalam Is `#ContentPlaceHolder1_CnfHide` the actual ID of the element? It this is asp.net then there is a chance that the ID is wrong. – Tim B James Aug 21 '13 at 10:23
  • i have taken in from page view source, and i am using same concept for other function, and that is working, so i don't think there is any problem with id – M Akela Aug 21 '13 at 10:24
0

There are a couple of ways to troubleshoot this behaviour.

  1. Your selector is returning no elements

    Change the Confirm function to this:

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

    If this returns 0, search your generated markup for CnfHide by viewing the source of the page in your browser and check that the id matches your selector.

    Seeing as you're using ASP.NET you might like to use this handy function which'll return elements with an ID ending with a value you specify. This is handy when you wrap your element in another server side control.

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

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

  2. The script is not being sent to the client

    Your can confirm this by viewing the source of the page in your browser and searching for something like if (confirm("Some columns are being use

    If you don't find this string on your page then you need to find out why the ScriptManager class isn't sending this data to the client.

    Here are some resources that might help you identify a server side problem

    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

Community
  • 1
  • 1
Zeb Rawnsley
  • 2,210
  • 1
  • 21
  • 33