C# javascript window.event出现空值?

C# javascript window.event出现空值?,c#,javascript,asp.net,regex,validation,C#,Javascript,Asp.net,Regex,Validation,我正在ASP.NET中使用CustomValidator,如下所示: <asp:CustomValidator ID="cvComment" ControlToValidate="txtComment" Display="None" EnableClientScript="true" ClientValidationFunction="validateComment" runat="server" ></asp:CustomValidator>

我正在ASP.NET中使用CustomValidator,如下所示:

<asp:CustomValidator ID="cvComment" ControlToValidate="txtComment" Display="None"
        EnableClientScript="true" ClientValidationFunction="validateComment"
    runat="server" ></asp:CustomValidator>
单击触发验证器的按钮后,应用程序中断,我可以看到
window.event
属性为null,因此显然有一个null引用试图匹配正则表达式。我的问题是为什么window.event会显示为null?我可以发誓这以前是有效的

编辑:

我已将函数修改为:

   var check = document.getElementById(source.id);
   var checky = check.attributes["controltovalidate"].value;
   var checkyo = document.getElementById(checky);
   var validHour = reOutHour.test(checkyo.value);
   if (!validHour)
        alert("The time is incorrectly formatted");
   args.IsValid = validHour;

现在这是在Internet Explorer上工作,而不是在Firefox上…

这就是我解决问题的方法:

var check = document.getElementById(source.id);
   var checky = check.controltovalidate;
   var checkyo = document.getElementById(checky);
   var validHour = reOutHour.test(checkyo.value);
   if (!validHour)
        alert("The time is incorrectly formatted");
   args.IsValid = validHour;

您正在测试哪个浏览器<代码>窗口。事件是IE专有的东西。在其他浏览器中,事件对象作为处理函数的第一个参数传递。如何修改它以支持两种浏览器?“source”(第一个参数)是要测试的DOM元素,使用它可以与任何浏览器兼容。“validateComment()”的这两个参数是什么?您能在ASP生成的mess中找到对该函数的实际调用吗?第一个参数(源)是测试的dom元素,第二个参数(args)包含一个属性isValid,您可以根据验证是否成功将其设置为true或false。
var check = document.getElementById(source.id);
   var checky = check.controltovalidate;
   var checkyo = document.getElementById(checky);
   var validHour = reOutHour.test(checkyo.value);
   if (!validHour)
        alert("The time is incorrectly formatted");
   args.IsValid = validHour;