简体   繁体   中英

How to call a asp button controls click event from another html(client side) button Control?

I was working on ASP.NET Gridview row delete, it was working fine.but when I tried to add popup delete confirmation, some problem came.

my delete button tag is:

<asp:TemplateField>
<ItemTemplate>
   <asp:Button  ID="btnDelete" runat="server" CssClass="CoolButtons" Text="Delete"           CommandName="Delete"  OnClick="btnEdit_Click" CommandArgument='<%# Container.DataItemIndex%>'/>
 </ItemTemplate>
</asp:TemplateField>

Now,I hv added some script for popup.NOTE: I hv used hidden field to use the value for server side delete event.

//***** 'Yes' button Click on Popup *****
            $("#btnYes").click(function (e) {
                HideDialog();
                e.preventDefault();
            });

            //***** 'No' Button click on Popup *****
            $("#btnNo").click(function (e) {

                $('input[id="hdnConfirmDelete"]').val("no");
                HideDialog();
                e.preventDefault();
            });

            //***** 'Delete' Button click on server ****
            $('input[value="Delete"]').click(function (e) {
               ShowDialog(true);
               e.preventDefault();


            });
 //**** Function to Open Dialog ***
            function ShowDialog(modal) {
                $("#overlay").show();
                $("#dialog").fadeIn(300);

                if (modal) {
                    $("#overlay").unbind("click");
                }
                else {
                    $("#overlay").click(function (e) {
                        HideDialog();
                    });
                }
            }
            //**** Function to Close Dialog ****
            function HideDialog() {
                $("#overlay").hide();
                $("#dialog").fadeOut(300);
            }

Now the problem is the I m not able to trigger the OnClick="btnEdit_Click" , I know its server side. Is there any way so that I can trigger the OnClick event of delete button when I click the " Yes " button on delete confirm dialog? NOTE: The dialog is made of simple HTML tags.

When you write e.preventDefault() it prevents the button from it's original working means server side code execution.
so use this

 $("#btnYes").click(function (e) {
            HideDialog();
        });

Remove the e.preventDefault();
Here is a link from where you can better understand

http://api.jquery.com/event.preventDefault/

Edit 1:-

use this

 $("#btnYes").click(function (e) {
            $('input[id="hdnConfirmDelete"]').val("yes");
            HideDialog();
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM