Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show * as the defaul text in a requiredfield

Status
Not open for further replies.
You want a "*" to show in the field(textbox?), or you want the validator to show it?
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.Validate()
End Sub
 
or are u talking bout the "*" sign that appears near mandatory fields...

Known is handfull, Unknown is worldfull
 
Yeah the * as the default showing text for a validator (mandatory field)
Is it possible to dislplay that before validation, then the error message after failing validation?

}...the bane of my life!
 
i.e. u want to display it in this format?

field *

field "oops, wrong" *


i guess just the placement of the controls will do that four u...

Known is handfull, Unknown is worldfull
 
u could do that with JS (really big workaround). will try to get u a sample dude...

Known is handfull, Unknown is worldfull
 
I'm not sure why you even need to go to any lengths like validating the page or using javascript functions. Simply include the asterisk in your label e.g.
Code:
    <div>
        <label for="TextBox1">TextBox1 (*):</label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
    </div>
You could also apply a CSS style to just the asterisk if you wanted to change it's font, color etc...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
he wants the * to disappear whn the error msg is displayed.

this is wht he wants:

field *

field "oops, wrong"


in the normal course wht u say holds good...

Known is handfull, Unknown is worldfull
 
If that's the case, I'd have to question the logic. If a field is required, I think there should always be something displayed to show it is required regardless of whether the user has actually completed it yet or not.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
My logic is that there will be somthing displayed.
* before a submit attempt
"Error Must be filled" if they try to submit the form without filling it in.

I can do it easily in javascrip tif i want, was just wondering if the validator can do it for you as I am new to .net

}...the bane of my life!
 
Yes, but what you're missing from that logic is when the user has typed something in. When they have done that, there will be nothing displayed to say that it was a required field (unless they remove what the typed in). With the method I suggested, it will be clear all of the time (and to those user withouth JS) that the field is required.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Yep, but i want the * gone if the validator is displaying the error message.
Not important, just an asthetic thing for me. The * will be there at all times except the error message

}...the bane of my life!
 
Yep, but i want the * gone if the validator is displaying the error message.
That's the part of the logic that I'm disagreeing with - I think that if the field is required the page should always show that it is required regardless of whether the user has attempted to fill it in or not.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
No, I'm saying the asterisk should be part of the label exactly like my example above showed. The error message should simply show the error if the user hasn't filled in the required field.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top