表格验证器“远程”网址不叫webmethod [英] Form validator "remote" url not calling webmethod

查看:61
本文介绍了表格验证器“远程”网址不叫webmethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临在表单验证中从远程验证器调用webmethod的问题。请帮我解决此问题。 

请检查我的代码:

**





 JQuery:





我尝试了什么:



 txtUsername:{
verbose:false,
验证器:{
notEmpty:{
message:'<%= Resources.LocalizedText .UserNameRequired%>'
},
stringLength:{
min:6,
max:30,
message:'<%= Resources.LocalizedText。 UserNameAtleastSixChars%>。'
},
regexp:{
regexp:/^[a-zA-Z0-9_\.]+$/,
message:' <%= Resources.LocalizedText.InvalidCharactersOnlylettersNumAndUnderscores%>'
},
remote:{
url:'/ BackOfficeOperations/HMS/SimpleHMS.aspx.cs/checkUsername',
type:'POST',

message:'<%= Resources .LocalizedText.UserNameAlreadyExists%>',
延迟:1000
}
}



}



代码





 [WebMethod] 
public static void checkUsername(string txtUsername)
{
var tsvc = new TenantService();
if(tsvc.UserNameExists(txtUsername))
HttpContext.Current.Response.Write({\valid\:false});
else
HttpContext.Current.Response.Write({\valid\:true});
}





 HTML 





< input class =form-controlname =txtUsername/> 

解决方案

/,
消息:'<%= Resources.LocalizedText.InvalidCharactersOnlylettersNumAndUnderscores%>'
},
remote:{
url :'/ BackOfficeOperations/HMS/SimpleHMS.aspx.cs/checkUsername',
类型:'POST',

消息:'<%= Resources.LocalizedText.UserNameAlreadyExists%>' ,
延迟:1000
}
}



}



代码





 [WebMethod] 
public static void checkUsername(string txtUsername)
{
var tsv c = new TenantService();
if(tsvc.UserNameExists(txtUsername))
HttpContext.Current.Response.Write({\valid\:false});
else
HttpContext.Current.Response.Write({\valid\:true});
}





 HTML 





< input class =form-controlname =txtUsername/> 

Quote:

 url:'/ BackOfficeOperations/HMS/SimpleHMS.aspx.cs/checkUsername'



这不是您网页的网址。这是代码隐藏文件的URL,无法远程访问,如果您编译了应用程序,甚至可能不存在。



尝试指定正确的URL对于你的页面,删除.cs:

 url:'/ BackOfficeOperations/HMS/SimpleHMS.aspx/checkUsername'


 I am facing issue for calling webmethod from remote validator in form validation.Please help me to resolve this issue.

Please check my code:

**



JQuery:



What I have tried:

txtUsername: {
                    verbose: false,
                    validators: {
                        notEmpty: {
                            message: '<%=Resources.LocalizedText.UserNameRequired%>'
                        },
                        stringLength: {
                            min: 6,
                            max: 30,
                            message: '<%=Resources.LocalizedText.UserNameAtleastSixChars%>.'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9_\.]+$/,
                            message: '<%=Resources.LocalizedText.InvalidCharactersOnlylettersNumAndUnderscores%>'
                        },
                        remote: {
                            url: '/BackOfficeOperations/HMS/SimpleHMS.aspx.cs/checkUsername',
                            type: 'POST',

                            message: '<%=Resources.LocalizedText.UserNameAlreadyExists%>',
                            delay: 1000
                        }
                    }



                }


code



[WebMethod]
   public static void checkUsername(string txtUsername)
   {
       var tsvc = new TenantService();
       if (tsvc.UserNameExists(txtUsername))
           HttpContext.Current.Response.Write("{\"valid\": false}");
       else
           HttpContext.Current.Response.Write("{\"valid\": true}");
   }



HTML



<input class="form-control" name="txtUsername" />

解决方案

/, message: '<%=Resources.LocalizedText.InvalidCharactersOnlylettersNumAndUnderscores%>' }, remote: { url: '/BackOfficeOperations/HMS/SimpleHMS.aspx.cs/checkUsername', type: 'POST', message: '<%=Resources.LocalizedText.UserNameAlreadyExists%>', delay: 1000 } } }


code



[WebMethod]
   public static void checkUsername(string txtUsername)
   {
       var tsvc = new TenantService();
       if (tsvc.UserNameExists(txtUsername))
           HttpContext.Current.Response.Write("{\"valid\": false}");
       else
           HttpContext.Current.Response.Write("{\"valid\": true}");
   }



HTML



<input class="form-control" name="txtUsername" />


Quote:

url: '/BackOfficeOperations/HMS/SimpleHMS.aspx.cs/checkUsername'


That's not the URL of your page. That's the URL of the code-behind file, which cannot be accessed remotely, and might not even exist if you've compiled your application.

Try specifying the correct URL for your page, by removing the ".cs":

url: '/BackOfficeOperations/HMS/SimpleHMS.aspx/checkUsername'


这篇关于表格验证器“远程”网址不叫webmethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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