开发者

asp.Net prevent server side link with javascript

开发者 https://www.devze.com 2023-02-10 07:18 出处:网络
I have an ImageButton as follows <asp:ImageButton OnClientClick=\"javascript:merge();\" ID=\"MenuLinkMerge\" Text=\"Merge\" ToolTip=\"Merge\" SkinID=\"Merge32\" runat=\"server\" oncl开发者_Python百

I have an ImageButton as follows

<asp:ImageButton OnClientClick="javascript:merge();" ID="MenuLinkMerge" Text="Merge" ToolTip="Merge" SkinID="Merge32" runat="server" oncl开发者_Python百科ick="MenuLinkMerge_Click" />

merge() will call

function merge() {
    if (IDList.length > 0) {
        alert("go");
        return true;
    } else {
        alert("No companies were selected.");
        return false;
    }
}

but whether I return true or false the MenuLinkMerge_Click is always called server side and the page is redirected. I only want the page to change if IDList.length > 0 otherwise display the alert and do nothing.

How do I accomplish this?


Change your onclientclick handler to this -> OnClientClick="return merge();"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号