Click here to Skip to main content
15,917,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I have a question i.e related to onclienclick event on imagebutton.It executes server click and page is postback(automatically itself refresh)while i give a javascript for this event thats not working.


how to stop postback on clientclick of an imagebutton??

thank you
Posted
Comments
amolpatil2243 27-Feb-12 1:34am    
have you added this client click event by attribute??? or directly to OnClientClick???
deepa5 27-Feb-12 1:36am    
directly on clientclick and my imagebuttion is used in updatepanel
Varun Sareen 27-Feb-12 1:38am    
Please post some code for more clarity
deepa5 27-Feb-12 1:39am    
<asp:ImageButton ID="ImgExportPdf" Height="20px" ImageUrl="~/images/pdf-icon.png"
runat="server" ToolTip="Export To Pdf" OnClientClick="javascript:return open_win();" />


and the javascript is this:

<script type="text/javascript">
function open_win() {

new window = window.open("ReadPdf.aspx", _blank);

return false;
}

</script>
Varun Sareen 27-Feb-12 2:52am    
why are you returning false? try to return true and then see it works or not.

Please refer these links for more clarity on OnClientClick event:-

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx[^]

http://weblogs.asp.net/skoganti/archive/2004/10/24/246980.aspx[^]

Please don't forget to mark this as your answer if it helps you out.
 
Share this answer
 
Hi, Write below code in Page load

C#
if(!isPostBack)
{
ImgExportPdf.Attributes.Add("onclick","javascript:return open_win();");
}
 
Share this answer
 
Comments
deepa5 27-Feb-12 2:09am    
nothing is wotking.Can anyone explain me this error comes because of Update Panel??
try this

<asp:imagebutton id="ImgExportPdf" height="20px" imageurl="~/images/pdf-icon.png" runat="server" tooltip="Export To Pdf" onclientclick="Javascript:return open_win();"/>

<script type="text/javascript">
function open_win() {
window.open("Default3.aspx");
return false;
} </script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900