Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
40
How to confirm when a button is clicked on client side before posting to server?
posted

I would like on client side to get confirmation like "Are you sure?" when a button on webtoolbar is clicked. I am trying with following script.

function tbMain_Click(oToolbar, oItem, oEvent){var btext = oItem.getText();

 

if (btext == "Release")

{

if (confirm("Are you sure?"))

{

oEvent.needPostBack =
true;

}

else

{

oEvent.cancel =
true;oEvent.needPostBack = false;

}

}

}

 

The script errors out  on this line. var btext = oItem.getText();

I do not know what is wrong?

 

  • 135
    posted

    Personally, I always use a switch on the button key, like so:

    function tbClick(oToolbar, oItem, oEvent)

    {

    switch (oItem.Key)

    {

    case "<%=ToolbarKey_Details%>": { processSelectedRows(details); break; }

    case "<%=ToolbarKey_History%>": { processSelectedRows(null, "<%=ResolveUrl("~/Pages/Application/ApplicationHistory.aspx")%>"); break; }

    }

    }

    Hurray for HTML whitespace. :)