asp.Net prevent server side link with javascript
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();"
精彩评论