调用javascript按钮单击事件时触发Page_load事件 [英] Page_load event firing while calling javascript button click event

查看:90
本文介绍了调用javascript按钮单击事件时触发Page_load事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过向按钮添加onclick属性来调用页面加载事件中的java脚本代码。

页面loding后我点击按钮。再次触发页面加载事件为什么?



我尝试了什么:



Dim sPath2 As String = System.Web.HttpContext。 Current.Request.ApplicationPath& _

/LicenseReport.aspx?SiteObjID=& intSiteObjid

btnLicenseReport.Attributes.Add(OnClick,javascript:LicenseReport('+ sPath2 +');)

解决方案

< blockquote> click事件只是在按钮的正常操作之前发生,所以你让你的js运行然后表单正常提交,以便页面进行回发。如果你想要停止帖子你的js需要返回false;



 btnLicenseReport.Attributes.Add(OnClick,javascript: LicenseReport('+ sPath2 +');返回false;)


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 + "');")

解决方案

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;")


这篇关于调用javascript按钮单击事件时触发Page_load事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆