我的web表单使用了asp:CustomValidator验证,所以ASP.NET写出了<form method="post" action="./MyPropertiesEnquiry.aspx?rwndrnd=0.30325462348842547" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">和
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}我需要发送一个命中事件到谷歌分析,如果验证已经成功,所以我假设我需要在return true;之前插入我的代码。
我已经看到了一个近乎解决方案的here
但是插入的代码对我来说放错了地方(它在WebForm_OnSubmit()的开头)。
发布于 2016-10-14 17:12:52
您可以简单地在此处添加您的CustomCode():
<form id="your_form_id" runat="server" onsubmit="CustomCode();">在此之后,您的WebForm_OnSubmit()将自动如下所示:
function WebForm_OnSubmit()
{
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false)
return false;CustomCode();
return true;
}发布于 2016-07-18 10:17:54
我做了一个Javascript函数覆盖,因为它看起来是最简单的技术,它有巨大的优势,能够精确地放置自定义代码。
WebForm_OnSubmit = function () {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
// Custom code here...
return true;
}我在我的网站上进行了测试,我可以将数据发送到Google Analytics,正如我所希望的那样。
https://stackoverflow.com/questions/38427397
复制相似问题