1

这是我在这个最伟大的网站上的第一篇文章。

是否有可能从 OnCheckUserName 函数更改 isValid 属性?如果可以,我该怎么做?

实际上在这个例子中有一个使用网络服务的代码块:

    <script type="text/javascript">
       function OnloginIDValidation(s, e) {
            if (e.value.toString().length > 0) {
                e.errorText = "UserName is not available";
                PageMethods.CheckUserName(e.value.toString(), OnCheckUserName);
            }
        }
        function OnCheckUserName(unavailable) {
            if (unavailable == true) {
                e.isValid = true;
            }
            else if (unavailable != true) {
                e.isValid = false;
            }
        }
    </script>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
     <dx:ASPxTextBox ID="txt_loginID" runat="server" AssociatedControlID="txt_loginID">
          <InvalidStyle BackColor="#FFF5F5">
               <Border BorderColor="Red" BorderStyle="Solid" BorderWidth="1px" />
          </InvalidStyle>
          <ClientSideEvents Validation="OnloginIDValidation" />
     </dx:ASPxTextBox>
    </asp:Content>
    [WebMethod]
    public static bool CheckUserName(string userName)
    {
        if (Membership.GetUser(userName) != null)
        {
          return true;
        }
        else
        {
          return false;
        }
    }

    private void ApplyValidationSummarySettings()
    {
        vsValidationSummary1.RenderMode = (ValidationSummaryRenderMode)Enum.Parse(typeof(ValidationSummaryRenderMode), "BulletedList");
        vsValidationSummary1.ShowErrorAsLink = true;
    }

    private void ApplyEditorsSettings()
    {
        ASPxEdit[] editors = new ASPxEdit[] {txt_loginID};
        foreach (ASPxEdit editor in editors)
        {
            editor.ValidationSettings.ValidateOnLeave = true;
            editor.ValidationSettings.SetFocusOnError = true;
        }
    }

它不起作用
我希望能帮助我如何解决它。
谢谢

4

2 回答 2

1

使用 JQuery 和 AJAX 检查以下链接以获取用户名可用性

http://www.aspsnippets.com/Articles/Check-UserName-Availability-in-ASP.Net-using-JQuery.aspx

http://www.aspsnippets.com/Articles/Check-Username-Availability-in-ASP.Net-using-AJAX-PageMethods.aspx

于 2012-04-10T13:32:22.287 回答
1

ASPxTextBox.ClientInstanceName属性设置为某个值,例如 textBox1。然后在方法中使用ASPxClientTextBox.SetIsValidOnCheckUserName方法。像这样:

    function OnCheckUserName(unavailable) {
        textBox1.SetIsValid(unavailable == true);
    }
于 2012-04-10T13:44:10.373 回答