【发布时间】:2014-02-21 01:23:41
【问题描述】:
我有一个 CustomValidator 和一个 RegularExpressionValidator,它们的可见性设置在后面的代码中。我想这样做,以便当页面不是回发时,控件不会在 html 文档中保留任何空间
注意:我已经尝试使用控件的动态显示设置,但这对我不起作用,因为它强制使用 display:inline 的内联样式,这会破坏我的布局
但是,这种情况非常适合我在页面中使用的 requirefieldvalidators。
以下是控件及其验证器的示例:
<dl class="accordion" data-accordion="">
<dd>
<a href="#PanelProductPricing">Product Pricing and Inventory</a>
<div id="PanelProductPricing" class="content active">
<fieldset>
<div class="row">
<%-- SALE PRICE ------------------------------------------%>
<div class="medium-4 small-12 columns">
<label>
Sale Price
<input id="tbPriceSale" type="text" placeholder="Sale Price" runat="server" />
<asp:CustomValidator runat="server" ID="cvPriceSale" ControlToValidate="tbPriceSale" EnableClientScript="true" Text="Please enter a sale price"
CssClass="error" ValidationGroup="AddProduct"
OnServerValidate="cvPriceSale_ServerValidate" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="tbPriceSale" Text="Invalid value for sale price"
ValidationExpression="^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$" ValidationGroup="AddProduct" CssClass="error" />
</label>
</div>
</div>
</fieldset>
</div>
</dd>
</dl>
所以在 页面加载 事件中,我有以下内容:
If Not Page.IsPostBack Then
rexvPriceSale.Visible = False
cvPriceSale.Visible = False
ElseIf Page.IsPostBack = True Then
rexvPriceSale.Visible = True
cvPriceSale.Visible = True
End If
以下是在输出 HTML 中为验证器控件呈现的内容:
<span id="dnn_ctr2601_AddProduct_cvPriceSale" class="error" style="visibility:hidden;">Please enter a sale price</span>
<span id="dnn_ctr2601_AddProduct_rexvPriceSale" class="error" style="visibility:hidden;">Invalidvalue for sale price</span>
问题
如您所见,在控件中添加了如下样式 style="visibility:hidden;"并且控件不可见,但它确实占用了屏幕中的“空间”。
我不知道这种风格是从哪里来的
我已尝试从回发中删除 visibility=true 并将其标记为 false,但无论我做什么,控件都会以完全相同的方式呈现。
问题:
有人可以帮我弄清楚为什么验证器会呈现可见性:无论我如何在服务器端代码中设置它们的可见性,它们都隐藏起来。
【问题讨论】: