Javascript web服务中的引用控件?

Javascript web服务中的引用控件?,javascript,jquery,asp.net,vb.net,Javascript,Jquery,Asp.net,Vb.net,我在一个调用web服务的文本框中有一个onBlur()函数。 web服务根据SQL表检查文本框中输入的电子邮件,查看它是否在那里,如果在那里,我需要它来停用ASP按钮。(再加上一些更精细的东西,但一旦我按下按钮,一切都会好起来的)。但是,每当我尝试引用web服务中的按钮控件(或任何其他ASP控件)时,我都会遇到一个错误“无法使用共享方法从引用类的实例成员…” 如何从web服务禁用按钮和更改面板的可见性? onBlur() 在VB.net中 txtEmail.Attributes.Add("onb

我在一个调用web服务的文本框中有一个onBlur()函数。 web服务根据SQL表检查文本框中输入的电子邮件,查看它是否在那里,如果在那里,我需要它来停用ASP按钮。(再加上一些更精细的东西,但一旦我按下按钮,一切都会好起来的)。但是,每当我尝试引用web服务中的按钮控件(或任何其他ASP控件)时,我都会遇到一个错误“无法使用共享方法从引用类的实例成员…”

如何从web服务禁用按钮和更改面板的可见性?

onBlur()

在VB.net中

txtEmail.Attributes.Add("onblur", CStr(IIf(c.AccountNo > 0, "", "CallMe(this.id,this.id);")))
在Jscript.js文件中

//AJAX Call to server side code
function CallMe(src, dest) {
aForgotPwd.style.display = 'none';
var ctrl = document.getElementById(src);
var cont = document.getElementById(btn);
var panel = document.getElementById(pnl);
 // call server side method
return PageMethods.ValidateEmail(ctrl.value, CallSuccess, CallFailed, dest);
}

// set the destination textbox value with the ContactName
function CallSuccess(res, destCtrl) {
var dest = document.getElementById(destCtrl);

if (res == "") {
    if(aForgotPwd.style.display != 'none')
    { aForgotPwd.style.display = 'none'; }

    return true;
} else {
    setTimeout("aForgotPwd.style.display='block';", 1);
    setTimeout("dest.focus();", 1);
    setTimeout("dest.select();", 1);
    alert("We have your email address already in our database. Please visit forgot your password page");


    return false;
}
//alert(res.get_message());
// var dest = document.getElementById(destCtrl);
}


// alert message on some failure

function CallFailed(res, destCtrl) {
var dest = document.getElementById(destCtrl);
 return true;
}
由CallMe()函数调用的Web服务

“电子邮件验证”
_
公共共享函数ValidateEmail(电子邮件作为字符串)作为字符串
Dim wbClient As WebClient=新WebClient()
Dim strUrl As String=ConfigurationManager.AppSettings(“WebsiteURLFull”)+“/ajax/check_email_address.aspx?email=“+email
以字节()形式显示HTML
reqHTML=wbClient.DownloadData(strUrl)
作为UTF8Encoding的Dim objUTF8=新UTF8Encoding()
Dim输出为String=objUTF8.GetString(reqHTML)
如果String.IsNullOrEmpty(输出),则
存在=错误
其他的
存在=真
btnContinue.enabled=False
如果结束
如果String.IsNullOrEmpty(输出),则返回String.Empty
作为GPCUser的dimc
如果HttpContext.Current.Session(“客户”)的类型是GPCUser,那么
c=CType(HttpContext.Current.Session(“客户”),GPCUser)
如果c.AccountNo>0,则返回“”
如果结束
返回输出
端函数

您不能在web服务方法中访问页面对象,而是可以在回调函数中禁用按钮和执行web服务后面板的可见性。只需从您的方法返回一条消息,说明电子邮件已存在或新。如果我不清楚,请告诉我

编辑 您可以在此链接中找到webmethod实现的更多详细信息

_
公共共享函数ValidateEmail(电子邮件作为字符串)作为字符串
Dim wbClient As WebClient=新WebClient()
Dim strUrl As String=ConfigurationManager.AppSettings(“WebsiteURLFull”)+“/ajax/check_email_address.aspx?email=“+email
以字节()形式显示HTML
reqHTML=wbClient.DownloadData(strUrl)
作为UTF8Encoding的Dim objUTF8=新UTF8Encoding()
Dim输出为String=objUTF8.GetString(reqHTML)
如果String.IsNullOrEmpty(输出),则
存在=错误
其他的
存在=真
'btnContinue.enabled=False
'注释按钮启用
输出=“禁用”
'将输出设置为禁用,以便在JS中可以禁用btn
如果结束
如果String.IsNullOrEmpty(输出),则返回String.Empty
作为GPCUser的dimc
如果HttpContext.Current.Session(“客户”)的类型是GPCUser,那么
c=CType(HttpContext.Current.Session(“客户”),GPCUser)
如果c.AccountNo>0,则返回“”
如果结束
返回输出
端函数

现在,在CallSuccess中,在继续使用功能之前,请检查res是否禁用,然后您可以禁用按钮并显示已存在的消息。

请将我解释为一个特别有挑战性的室内设备。三天来我一直在和这乱七八糟的东西碰头。这是我的第一份开发工作,我实际上没有接受VB的培训,所以这让我有点困惑。谢谢!我知道你从哪里来了。CallSuccess()函数已经将输出字符串用作可用结果。我可以不把它塞进里面吗?还有,有点相关,因为它是一个单独的.js文件,我知道我不能使用服务器端代码来获取客户端id(“”)。但是,如果我使用静态客户端ID,它也不起作用。
'Email Validation
<System.Web.Services.WebMethod()> _
Public Shared Function ValidateEmail(email As String) As String
    Dim wbClient As WebClient = New WebClient()
    Dim strUrl As String =  ConfigurationManager.AppSettings("WebsiteURLFull") + "/ajax/check_email_address.aspx?Email=" + email
    Dim reqHTML As Byte()
    reqHTML = wbClient.DownloadData(strUrl)
    Dim objUTF8 As UTF8Encoding = New UTF8Encoding()
    Dim output As String = objUTF8.GetString(reqHTML)
   If String.IsNullOrEmpty(output) Then
        exists = False
    Else
        exists = True
        btnContinue.enabled = False
    End If
    If String.IsNullOrEmpty(output) Then Return String.Empty
    Dim c As GPCUser

    If TypeOf HttpContext.Current.Session("Customer") Is GPCUser Then
        c = CType(HttpContext.Current.Session("Customer"), GPCUser)

        If c.AccountNo > 0 Then Return ""
    End If



    Return output
End Function
<System.Web.Services.WebMethod(EnableSession:=True)> _
Public Shared Function ValidateEmail(email As String) As String
Dim wbClient As WebClient = New WebClient()
Dim strUrl As String =  ConfigurationManager.AppSettings("WebsiteURLFull") + "/ajax/check_email_address.aspx?Email=" + email
Dim reqHTML As Byte()
reqHTML = wbClient.DownloadData(strUrl)
Dim objUTF8 As UTF8Encoding = New UTF8Encoding()
Dim output As String = objUTF8.GetString(reqHTML)
If String.IsNullOrEmpty(output) Then
    exists = False
Else
    exists = True
    'btnContinue.enabled = False
    'Commenting the Button enabling
     output="disable"
     'Assinging the output as disable so that in JS you can disable btn
End If
If String.IsNullOrEmpty(output) Then Return String.Empty
Dim c As GPCUser

If TypeOf HttpContext.Current.Session("Customer") Is GPCUser Then
    c = CType(HttpContext.Current.Session("Customer"), GPCUser)

    If c.AccountNo > 0 Then Return ""
End If

 Return output
End Function