【发布时间】:2011-09-29 22:32:19
【问题描述】:
我的页面上有几个带有复选框的模式弹出窗口。复选框是可以添加到特定产品的不同项目。但是,有些产品分配了一种类型的项目。当模态框为空时,我需要一种在模态框中显示消息的方法。
我尝试在模式中使用“所有功能当前都与此产品相关联”的标签。但是当标签的可见性设置为隐藏时,标签会在模式中留下一个空间,这很烦人,所以我放弃了这个想法。
当模态框为空时显示隐藏消息的好方法是什么?
<asp:LinkButton ID="FeatureButton" runat="server">Feature</asp:LinkButton>
<asp:Panel ID="FeaturePanel" runat="server" CssClass="modalPopup"
Style="display:none">
<div class="PopupHeader">Add a Feature</div>
<asp:CheckBoxList ID="cbxAddFeature" runat="server"
DataSourceID="dsNewFeatures" DataTextField="FeatureTitle"
DataValueField="FeatureID"></asp:CheckBoxList>
**<asp:Label ID="FeatureError" runat="server"
Text="All features are currently associated to this product."
Display="none"></asp:Label>**
<asp:Button ID="SubmitFeatures" runat="server" Text="Submit" />
<asp:Button ID="CancelSubmitFeatures" runat="server" Text="Cancel" />
</asp:Panel>
<asp:ModalPopupExtender ID="FeatureModal" runat="server"
BackgroundCssClass="modalBackground" CancelControlID="CancelSubmitFeatures"
DropShadow="True" DynamicServicePath="" Enabled="True"
PopupControlID="FeaturePanel" TargetControlID="FeatureButton">
</asp:ModalPopupExtender>
Protected Sub SubmitFeatures_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles SubmitFeatures.Click
FeatureModal.Hide()
For Each feature As ListItem In cbxAddFeature.Items
**FeatureError.Visible = False**
If feature.Selected Then
'SQL INSERT: Marketing Table
Dim strSQL As String = "INSERT INTO Marketing (ProductID, MarketingTypeID, MarketingTitle, MarketingData) VALUES (@ProductID, 3, 'Feature', @MarketingData)"
Using cn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
Using cmd As New SqlCommand(strSQL, cn)
cmd.Parameters.Add(New SqlParameter("@ProductID", ProductID.Value))
cmd.Parameters.Add(New SqlParameter("@MarketingData", feature.Value))
cn.Open()
cmd.ExecuteNonQuery()
End Using
End Using
End If
**If (dsNewFeatures) == DBNull.Value Then
FeatureError.Visible = True
End If**
Next
Response.Redirect(Request.RawUrl)
End Sub
<asp:SqlDataSource ID="dsNewFeatures" runat="server"
ConnectionString="<%$ ConnectionStrings:ProductsConnectionString %>"
ProviderName="<%$ ConnectionStrings:ProductsConnectionString.ProviderName %>"
SelectCommand="SELECT DISTINCT f.FeatureID, f.FeatureTitle
FROM Feature f LEFT JOIN Category c ON c.CategoryID = f.CategoryID
WHERE f.CategoryID IN
(SELECT CategoryID FROM CategoryLink
WHERE ProductID = @ProductID) AND f.FeatureID NOT IN
(SELECT m.MarketingData FROM Marketing m
WHERE m.MarketingTypeID = 3 AND m.ProductID = @ProductID)
ORDER BY f.FeatureTitle">
<SelectParameters>
<asp:QueryStringParameter Name="ProductID" QueryStringField="id" />
</SelectParameters>
<SelectParameters>
<asp:QueryStringParameter Name="CategoryID" QueryStringField="id" />
</SelectParameters>
</asp:SqlDataSource>
所有 **** 项都是标签的一部分,If, End If 语句不起作用,有谁知道我可以如何更改它以找到错误消息的空模式?
这就是现在的样子,注意显示的标签。我不知道为什么它不会消失!
编辑 9/29/11
Protected Sub dsNewFeatures_Selected(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles dsNewFeatures.Selected
If FeatureError.Text = String.Format("rows count: {0}", e.AffectedRows) Then
FeatureError.Visible = True
Else
FeatureError.Visible = False
End If
End Sub
它几乎可以工作!仅根据此代码,标签不可见,但是当我清空模式时无法取消隐藏
【问题讨论】:
-
简单地将“Display = none”添加到 asp:label 标记并不能消除空格。空白之所以存在,是因为 asp.net 隐藏控件的默认行为仍会在呈现的文档流中为它们留出空间。要解决此问题,您可以尝试将 For Each 循环中的 FeatureError.Visible = False 更改为 FeatureError.Attributes.Add("Style", "Display:None;") .该样式应将其从文档流中删除。这是一个链接,描述了我要更详细地解释的内容。 w3schools.com/css/css_display_visibility.asp
-
我试了属性码,还是出现空格。我不知道它为什么在那里,但我必须习惯它在那里,因为我无法让它消失哈哈
标签: asp.net sql vb.net checkbox label