Question

I have a asp:Button, I want to call javascript function before ConfirmButtonExtender takes action. But my javascript code is not working. Please tell me how to use ConfirmButtonExtender with javascript.

<asp:Button ID="UpdatebuttonUpdaterID" runat="server" Text="Update" CssClass="create_role_button_in"
                                    OnClick="UpdatebuttonUpdaterID_Click" OnClientClick="return OnClientClickUpdate();"/>
                                    <ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender3" runat="server" TargetControlID="UpdatebuttonUpdaterID"
                                    ConfirmText="Do you want to send this Conversion Rate for Approval?" ConfirmOnFormSubmit="true" OnClientCancel="CancelClick"/>

This is my javascript code.

    function OnClientClickUpdate() {

                alert("hello");
}
Was it helpful?

Solution

You can use the Behavior property of the ConfirmButtonExtender and add the javascript function to it, this way the javascript function will be called before the ConfirmText property of the ConfirmButtonExtender.

Modify your markup to the following:

<asp:Button ID="UpdatebuttonUpdaterID" runat="server" Text="Update" CssClass="create_role_button_in"
                                    OnClick="UpdatebuttonUpdaterID_Click" OnClientClick="return OnClientClickUpdate();"/>
                                    <ajaxToolkit:ConfirmButtonExtender BehaviorID="confirmBehavior" ID="ConfirmButtonExtender3" runat="server" TargetControlID="UpdatebuttonUpdaterID"
                                    ConfirmText="Do you want to send this Conversion Rate for Approval?" ConfirmOnFormSubmit="true" OnClientCancel="CancelClick"/>   
 <script type="text/ecmascript">
        Sys.Application.add_load(wireEvents);

        function wireEvents() {
            var behavior = $find("confirmBehavior");
            behavior.add_showing(OnClientClickUpdate);
        }

        function OnClientClickUpdate() {
            alert("hello");
        }
    </script>

Hope it helps, source for this answer Here.

OTHER TIPS

You can give up using the confirm extender (unlees you really need it) and use javascript:

function OnClientClickUpdate()
{
   alert("first click");
   //do some stuff
   return confirm("are you sure?");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top