Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am calling java script code in page load event by adding onclick attribute to button.
After page loding i am click the button.it again firing page load event why?

What I have tried:

Dim sPath2 As String = System.Web.HttpContext.Current.Request.ApplicationPath & _
"/LicenseReport.aspx?SiteObjID=" & intSiteObjid
btnLicenseReport.Attributes.Add("OnClick", "javascript:LicenseReport('" + sPath2 + "');")
Posted
Updated 9-Aug-16 22:07pm

1 solution

The click event simply happens before the button's normal action, so you get your js running and then the form submits as normal so the page does a postback. If you want to stop the post back your js needs to return false;

btnLicenseReport.Attributes.Add("OnClick", "javascript:LicenseReport('" + sPath2 + "');return false;")
 
Share this answer
 
Comments
User-11630313 10-Aug-16 4:27am    
you are awesome bro...Thankyou its working

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



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