Static validators emitting "nbsp;"
I have a .NET question. For my particular application which is catoring to 开发者_开发问答mobile devices (specifically blackberry at the moment), I am using validators (required field validator to be exact).
The problem is that I have disabled javascript from asp.net (by specifying ClientTarget="ie4", but setting EnableClientScript="False" on the validator tags has the same effect). The actual issue is that when the validator is invisible, it emits "nbsp;" instead of nothing, is there some way to override this unwanted result?
Please do not reply solutions that include css or javascript, as I am unable to use either in my particular situation.
Thank you.
Display=Static means that a single nonbreaking space (" ") is emitted. This last behavior exists so that table cells containing only validators do not collapse to nothing when valid.
From here.
As Frédéric Hamidi said, you could try Display=Dynamic
instead, but if you're insistent on using Display=Static
, I think your only option is to extend the validator and override the Render
method.
protected override void Render(HtmlTextWriter writer)
{
if (this.Display == ValidatorDisplay.Static && this.IsValid)
{
writer.Write(String.Empty);
}
else
{
base.Render(writer);
}
}
Static validators will indeed render an
entity when hidden.
Try using dynamic validators instead, by setting their Display property to ValidatorDisplay.Dynamic
.
精彩评论