Asp.Net Linkbutton force it to not postback

Is there anyway that I can make a linkbutton not postback but instead run a javascript?
johnywhiteAsked:
Who is Participating?
 
Sam_JayanderCommented:
Hi,
Try adding a "return false;" as the last line in the javascript. It works for me.

eg:
LinkButton1.Attributes.Add("onClick","javascript:alert('Hello World!');return false;");

HTH,
--Sam.
0
 
Rajulkumar PatelSenior Technical LeadCommented:
Hi,

The only one way is add a attribute to linkbutton in page load event.


LinkButton1.Attributes.Add("onClick","JavaScript:return false;");


Thanks
0
 
RejojohnyCommented:
mrrajpatel, how is this different from what Sam has suggested above?

johnywhite, pls close this question if its been answered .. it saves time for people like us who are browsing the open questions ..

Rejo
0
 
johnywhiteAuthor Commented:
I haven't had a chance to test it but I assume it works.
0
 
gtzpowerCommented:
Worked fine for me.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.