使用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. This works great without the RequiredFieldValidator on the form. When it's on the form, I get an error:

我在使用RequiredFieldValidator時從代碼后面調用jQuery方法時遇到問題。沒有表單上的RequiredFieldValidator,這很好用。當它在表單上時,我收到一個錯誤:

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. When you click the button, it fires the server side OnClick method with the following code:

作為測試,我有一個簡單的頁面,其上有一個TextBox和一個UpdatePanel中的按鈕。單擊該按鈕時,它將使用以下代碼觸發服務器端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. Does anyone have any ideas what might be causing this?

這很好用,並彈出消息。當我將一個RequiredFieldValidator附加到TextBox時,會彈出錯誤。有沒有人有任何想法可能導致這個?

1 个解决方案

#1


0  

Add this to your Required Field Validator:

將其添加到您的必填字段驗證器:

EnableClientScript="false"

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/10/04/725188d99a277ad3f4ce175e6a728e05.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com