Calling Jquery function from GridView link

白昼怎懂夜的黑 提交于 2019-12-25 18:27:38

问题


After hours of trying every possible way, I give up. Maybe you guys can see what i'm doing wrong here. I have a GridView with a Delete button. On the ClientClick event i call a javascript function that opens a jquery msgbox with yes/no buttons. If the user clicked yes, I would like the function ConfirmDeleteRecord() to return true.

This is how the "Delete" column on the GridView looks like:

<asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
        <asp:LinkButton CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ClientSkuID") %>' Text="Delete" runat="server" ID="lnkDelete" OnClientClick="return ConfirmDeleteRecord()"></asp:LinkButton>
    </ItemTemplate>

This is my Javascript function:

function ConfirmDeleteRecord() {

var bResult = false;

$.msgBox({
    title: "Are You Sure?",
    content: "Are you sure you want to delete this record?",                    
    type: "confirm",
    buttons: [{ value: "Yes" }, { value: "No" }, { value: "Cancel"}],
    success: function (result) {
        if (result == "Yes") {
            bResult = true;
        }
    }
    });


return bResult;

}

The problem is that the code never get to to "return bResult" line.

Thank you all.


回答1:


That won't work because $.msgBox is not a blocking function like confirm() is. Make sense? All that function is doing is showing some HTML. What you need to do is instead change your code from this:

 if (result == "Yes") {
            bResult = true;
        }

To something like:

if (result == "Yes") {
 //perform postback here to delete the record. 
}


来源:https://stackoverflow.com/questions/13782051/calling-jquery-function-from-gridview-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!