这是我在这个最伟大的网站上的第一篇文章。
是否有可能从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;
}
}
它不起作用
我希望能帮到我如何解决它。
感谢
答案 0 :(得分:1)
使用JQuery&amp; amp;检查以下链接用户名可用性的AJAX
http://www.aspsnippets.com/Articles/Check-UserName-Availability-in-ASP.Net-using-JQuery.aspx
答案 1 :(得分:1)
将ASPxTextBox.ClientInstanceName属性设置为某个值,例如textBox1的。然后在OnCheckUserName
方法中使用ASPxClientTextBox.SetIsValid方法。
像这样:
function OnCheckUserName(unavailable) {
textBox1.SetIsValid(unavailable == true);
}