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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying an error?

Status
Not open for further replies.

Everton1Blue

Technical User
Jun 6, 2014
41
GB
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:

TekTips_silr7o.jpg


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.
 
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!
 
Thank you Jebenson.

The JS route sounds laborious.

What about .skin?

 

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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top