Z
zlusca
Hi, guys
I have asp.net form contain several textbox controls and one field is
userName I want to validate this field to make sure there is no other
user have the same userName before saving. so I create a
customValidator to do that. The strange thing is that customValidator
never fired the validation event.
Here is the code:
in aspx file the control is:
<DIV><SPAN class="form_label">Username</SPAN>
<SPAN class="form_field">
<asp:TextBox id="userName" Runat="server"
CssClass="NormalTextBox" MaxLength="25"></asp:TextBox>
<asp:RequiredFieldValidator id="userNameRequiredfieldvalidator"
Runat="server" Display="Static" ErrorMessage="User Name is Required
Field."
ControlToValidate="userName"
NAME="userNameRequiredfieldvalidator"></asp:RequiredFieldValidator>
<asp:CustomValidator id="userNameCustomValidator" runat="server"
Display="static" ErrorMessage="error"></asp:CustomValidator>
</SPAN></DIV>
in aspx.cs file:
private void InitializeComponent(){
this.userNameCustomValidator.ServerValidate += new
System.Web.UI.WebControls.ServerValidateEventHandler(this.userNameCustomValidator_ServerValidate);
}
private void userNameCustomValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
args.IsValid = false;
}
I set a breakpoint inside the validation funtion, but seem like the
application never go through the function.
I could not figure out what the problem is. Please help. Thanks!
I have asp.net form contain several textbox controls and one field is
userName I want to validate this field to make sure there is no other
user have the same userName before saving. so I create a
customValidator to do that. The strange thing is that customValidator
never fired the validation event.
Here is the code:
in aspx file the control is:
<DIV><SPAN class="form_label">Username</SPAN>
<SPAN class="form_field">
<asp:TextBox id="userName" Runat="server"
CssClass="NormalTextBox" MaxLength="25"></asp:TextBox>
<asp:RequiredFieldValidator id="userNameRequiredfieldvalidator"
Runat="server" Display="Static" ErrorMessage="User Name is Required
Field."
ControlToValidate="userName"
NAME="userNameRequiredfieldvalidator"></asp:RequiredFieldValidator>
<asp:CustomValidator id="userNameCustomValidator" runat="server"
Display="static" ErrorMessage="error"></asp:CustomValidator>
</SPAN></DIV>
in aspx.cs file:
private void InitializeComponent(){
this.userNameCustomValidator.ServerValidate += new
System.Web.UI.WebControls.ServerValidateEventHandler(this.userNameCustomValidator_ServerValidate);
}
private void userNameCustomValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
args.IsValid = false;
}
I set a breakpoint inside the validation funtion, but seem like the
application never go through the function.
I could not figure out what the problem is. Please help. Thanks!