gpt4 book ai didi

html - 将 asp Validator 的可见性设置为 True 不会影响任何更改

转载 作者:太空宇宙 更新时间:2023-11-03 18:20:35 25 4
gpt4 key购买 nike

我有一个 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,但无论我做什么,控件都以完全相同的方式呈现。

问题:

谁能帮我弄清楚为什么无论我如何在服务器端代码中设置它们的可见性,验证器都以 visibility:hidden 呈现。

最佳答案

尝试在它们周围放置一个 asp:PlaceHolder,并改为设置它的可见性。

关于html - 将 asp Validator 的可见性设置为 True 不会影响任何更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21923331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com