我的頁面上有幾個模式彈出窗口,顯示覆選框。複選框是可以添加到特定產品的不同項目。但是,某些產品分配了所有類型的項目。當模態爲空時,我需要一種方式在模態中顯示消息。模式爲空時出現錯誤信息
我已經嘗試在模式中使用標籤「所有功能當前與此產品相關聯」。但是當標籤的可見性被設置爲隱藏並且很煩人時,標籤在模式中留下空間,所以我放棄了這個想法。
有什麼方法可以在模態爲空時顯示隱藏信息?
<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>
所有****項目是標籤件,如果END IF語句不工作,沒有人知道我怎樣才能改變這種狀況得到它找到的錯誤消息的空模態?
這是它看起來像現在,請注意標籤顯示。我不知道它爲什麼不會消失!
編輯11年9月29日
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
它幾乎作品!標籤不可見僅基於此代碼,但當我清空模式時,無法取消隱藏
簡單地增加「顯示=無」到ASP:標籤標記不會做刪除空間的伎倆。存在空白區域是因爲asp.net的隱藏控件默認行爲仍然會在渲染文檔流中留下空間。爲了解決這個問題,你可以嘗試改變你的For Each循環中的** FeatureError.Visible = False **爲** FeatureError.Attributes.Add(「Style」,「Display:None;」)**。該樣式應將其從文檔流中移除。這裏有一個鏈接,描述了我想要更詳細解釋的內容。 http://www.w3schools.com/css/css_display_visibility.asp – CheckRaise
我試過了屬性代碼,空間仍然顯示出來。我不知道爲什麼它在那裏,但我只需要習慣它在那裏,因爲我無法讓它離開哈哈 – jlg