INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Displaying an error?

Displaying an error?

(OP)
Hello

I have lost my way a bit on this. I have a form here: Link If I complete all fields correctly the user is directed to a 'thank you' page and that works fine, but if the user omits the Name field, for
example, a red error message says 'Please complete the Name field' like this:



Not only does this look untidy, but it has displaced the Email label, pushing it into the form. Ideally, I would like the error message displayed on one line INSIDE the Name field itself, but I'm not sure how to do that.

The code for the Name field looks like this:

CODE -->

<p><asp:Label ID="Name" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="your_name" runat="server"></asp:TextBox></p>

<asp:RequiredFieldValidator Display="None" ID="RequiredFieldValidator1" runat="server"  controlToValidate="your_name" ForeColor="#FF6666" ErrorMessage="Please complete the Name field"></asp:RequiredFieldValidator> 

Thanks for any advice.

RE: Displaying an error?

You need to put some sort of layout on your form, either divs, panels or a table, so you can have a space already dedicated to the error message that won't change the layout of the other elements on the page. Something like this:

<div>
<p><asp:Label ID="Name" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="your_name" runat="server"></asp:TextBox></p>
</div>

<div>
<asp:RequiredFieldValidator Display="None" ID="RequiredFieldValidator1" runat="server" controlToValidate="your_name" ForeColor="#FF6666" ErrorMessage="Please complete the Name field">
</asp:RequiredFieldValidator>
</div>

<div>
<other elements on form>
<div>

This won't put the error message in the textbox. I don't think the RequiredFieldValidator can do that. If you really want the error message in the textbox you'll have to code it all yourself, including JavaScript to clear the error message when the user clicks on the textbox.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: Displaying an error?

(OP)
Thank you Jebenson.

The JS route sounds laborious.

What about .skin?

RE: Displaying an error?


I don't think so. Skins are for controlling the appearance of elements in a form. As far as I know, they do not address the layout.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close