Custom error UI using requiredfieldvalidator assistance needed
Allow me to thank you in advance.
I'm presently using a standard asp.net control to validate a (Name) text field. As you can see by the code, I have moved the asterisk to the left of the textbox label (rather than put it next to the text box). What I would like to do it show the asp.net error "*" in place of the "<span class="required-asterisk">*</span>"
So if the user has no error they will see the <span class="required-asterisk">*</span> which is blue for example. However, if they have an error the blue "*" will be replaced by the asp.net default "*".
This is my code:
<asp:requiredfieldvalidator id="Name" runat="server" controltovalidate="Name" enableclientscript="True">*</asp:requiredfieldvalidator>
Basically I would like something similar to an esle statement.
Any help would be greatly appreciated.
I would use the CustomValitator control. That way you can use an if statement to determine whether valid input was entered. Something like this may suffice.
The following article explains how to use the control (if you do not already know how to): http://aspnet.4guysfromrolla.com/articles/073102-1.aspx
sub ValidateField(Sender As Object, Args As ServerValidateEventArgs)
If Args.Value = Nothing Then
ErrMessage.Style("color") = "Red"
Args.IsValid = False
ErrMessage.Style("color") = "Blue"
Args.IsValid = True
<asp:CustomValidator runat="server" id="custVal_Name"
<span id="ErrMessage" style="color:blue;" runat="server">*</span>
Also, you have posted in the incorrect forum. I will move this to the ASP.NET for you.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)