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");
}
有帮助吗?

解决方案

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.

其他提示

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?");
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top