2012-04-10 42 views
1

這是我在這個最偉大的網站的第一篇文章。ASP.NET檢查用戶名可用性使用ClientSideEvents

有沒有可能從OnCheckUserName函數改變isValid屬性?如果是的話我該怎麼做?

其實在這個例子中有是使用Web服務的代碼塊:

<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; 
     } 
    } 

它不工作
我希望能幫助我,我怎麼能解決這個問題。
感謝

回答