简体   繁体   English

使用RequiredFieldValidator时,jQuery方法无法从代码后面触发

[英]JQuery method not firing from code behind when using a RequiredFieldValidator

I'm having a problem with a jQuery method being called from code behind when using a RequiredFieldValidator. 我在使用RequiredFieldValidator时从后面的代码中调用jQuery方法时遇到问题。 This works great without the RequiredFieldValidator on the form. 在窗体上没有RequiredFieldValidator的情况下,这很好用。 When it's on the form, I get an error: 在表单上时,出现错误:

Microsoft JScript runtime error: Object doesn't support property or method 'toastmessage' Microsoft JScript运行时错误:对象不支持属性或方法“ toastmessage”

as if it hasn't loaded the jquery.js file. 好像它尚未加载jquery.js文件。

As a test, I have a simple page that has a TextBox on it and a button within an UpdatePanel. 作为测试,我有一个简单的页面,上面有一个TextBox和一个UpdatePanel中的按钮。 When you click the button, it fires the server side OnClick method with the following code: 当您单击按钮时,它将使用以下代码触发服务器端的OnClick方法:

        ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", @"$().toastmessage('showWarningToast', 'Record Saved Successfully.'); ", true);

This works great, and pops the message. 这很好用,并弹出消息。 When I attach a RequiredFieldValidator to the TextBox is when the error pops up. 当我将RequiredFieldValidator附加到TextBox时会弹出错误。 Does anyone have any ideas what might be causing this? 有谁知道这可能是什么原因?

将此添加到您的必填字段验证器中:

EnableClientScript="false"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM