RequiredFieldValidator

mozzer

New Member
I can't figure out why these controls are rendering such that they take up space...ie, if I place it under field I want to validate it, it pushes the rest of the page down even when it's not visible. Here's the HTML being rendered:<BR><BR><span id="RequiredFieldValidator1" controltovalidate="CompanyName" errormessage="You must enter a company name." evaluationfunction="RequiredFieldValidatorEvaluateIsValid" initialvalue=http://aspmessageboard.com/archive/index.php/"" style="color:Red;visibility:hidden;">You must enter a company name.</span><BR><BR>Apparently the "<span>" is taking up space on the page even though it's not visible? Someone tell me how to get around this.Hi, <BR>I know I had that problem at one point. But I had my display set to static. I'm not sure if the display type default is static, but if you put:<BR>Display="Dynamic"<BR>in your asp tag on you aspx page, that should help.try this as a replacement <BR><BR><asp:requiredfieldvalidator controltovalidate="CompanyName" display="dynamic" errormessage="<span style='color:Red'>You must enter a company name.</span>"><BR><BR>You'll notice that A) I added display="dynamic" B) moved the <span> tags INSIDE of your errormessage C) placed your style attributes in single quotes D) removed some excess code E) Made your tag a true vb.net requiredvalidator tag.<BR><BR>I did notice that you had the message "You must enter a company name." displaying then hiding. I really don't recommend this. It would be easier to do something else.To clarify on your changes, this was the code being generated by .NET after inserting requiredfieldvalidators. I did not have a span defined, nor did I have anything between the opening and closing tags. That's how .NET rendered it to the browswer.Perfect that fixed it!<BR><BR>You know, I had actually messed with that yesterday, but I was trying to fix a different problem (I had to move my "IsPostBack" handler out of the Page_Load event to get the validators to work) and today I completely forgot about the dynamic thing. Thanks a lot!I'm assuming you are using VS.NET? It's no suprise it added extra lines of code, frontpage was the same way. Just try what I gave you and post any problems you have with it.I don't think you're quite tracking. They aren't extra lines of code that VS.NET inserted in the editor...those are the lines are code that are RENDERED to the browser by the .NET server. The only problem was changing display to dynamic instead of static. It works fine now. But the whole <span></span> inside the validator tags are no where to be found in the code page itself, that's my point.Strange that the extra code was being renedered. SPAN tags do not accept those attributes ,except for the style tag, in HTML therefore they shouldn't have done anything. What I can surmise s that the style tag had a hidden attribute which means your ERRORMESSAGE tag from the requiredfieldvalidator was showing THEN your static display of "You must enter a company name" was being hidden YET it was still taking up space and thus pushing your form down. Anyway glad you've got it fixed.
 
Back
Top