 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 29th, 2007, 08:58 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Hide control and not take up space
I am trying to manipulate controls based upon a value in my database.
For example, I have a Painting table that stores the "Painting Type". Based upon the Painting Type, I wish to hide particular label's in my formview. The formview is set to display all the values for the object. I've tried various different methods, even changing the control's "CSSCLass" to one that has "display:none" but it still reserves space.
Here is my part of my page:
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("URL", "~/Paintings/{0}") %>' Width="700px" /><br /><br />
<span style="font-weight:bold; color:Blue;">Title:</span>
<asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>'></asp:Label><br />
<span style="font-weight:bold; color:Blue; vertical-align:text-top">Comments:</span><br />
<asp:Label ID="CommentsLabel" runat="server" Text='<%# Bind("Comments") %>' Width="600px"></asp:Label><br />
<asp:Label ID="PrintAvailableTextLabel" runat="server" Text="Print Available:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:HiddenField ID="HiddenField1" runat="server" value = '<%# Bind("PrintAvail") %>'/>
<asp:Label ID="PrintAvailLabel" runat="server"></asp:Label><br />
<asp:Label ID="NoteCardAvailableTextLabel" runat="server" Text="Note Card Available:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:HiddenField ID="HiddenField2" runat="server" value = '<%# Bind("NotecardAvail") %>' />
<asp:Label ID="NotecardAvailLabel" runat="server" ></asp:Label><br />
<asp:Label ID="SizeTextLabel" runat="server" Text="Size:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:Label ID="SizeLabel" runat="server" Text='<%# Bind("Size") %>'></asp:Label><br />
<asp:Label ID="ValueTextLabel" runat="server" Text="Value" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:Label ID="ValueLabel" runat="server" Text='<%# Bind("Value") %>'></asp:Label><br />
<asp:Label ID="PrintValueTextLabel" runat="server" Text="Print Value:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:Label ID="PrintValueLabel" runat="server" Text='<%# Bind("printValue") %>'></asp:Label><br />
<asp:Label ID="PrintSizeTextLabel" runat="server" Text="Print Size:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:Label ID="PrintSizeLabel" runat="server" Text='<%# Bind("printSize") %>'></asp:Label><br />
</ItemTemplate>
</asp:FormView>
Here is my code behind:
Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
If Request.QueryString("ptype") = 2 Then
CType(FormView1.FindControl("PrintAvailLabel"), Label).CssClass = "hide"
CType(FormView1.FindControl("NotecardAvailLabel"), Label).CssClass = "hide"
CType(FormView1.FindControl("SizeLabel"), Label).CssClass = "hide"
CType(FormView1.FindControl("ValueLabel"), Label).CssClass = "hide"
CType(FormView1.FindControl("PrintAvailableTextLab el"), Label).CssClass = "hide"
CType(FormView1.FindControl("NoteCardAvailableText Label"), Label).CssClass = "hide"
CType(FormView1.FindControl("SizeTextLabel"), Label).CssClass = "hide"
CType(FormView1.FindControl("ValueTextLabel"), Label).CssClass = "hide"
Else
CType(FormView1.FindControl("PrintValueLabel"), Label).CssClass = "hide"
CType(FormView1.FindControl("PrintSizeLabel"), Label).CssClass = "hide"
CType(FormView1.FindControl("PrintValueTextLabel") , Label).CssClass = "hide"
CType(FormView1.FindControl("PrintSizeTextLabel"), Label).CssClass = "hide"
End If
End Sub
I have also tried ".visible=false"
I have tried different Routines too..for example, Pageload, Pageinit..(I have to admit, I wish I knew the order the events triggered----but not entirely sure that is it).
any help would be appreciated!
Kind Regards,
Rob
|
|

August 29th, 2007, 09:25 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
I figured this out after some research. I was not aware of the placeholder, I rewrote so that:
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("URL", "~/Paintings/{0}") %>' Width="700px" /><br /><br />
<span style="font-weight:bold; color:Blue;">Title:</span>
<asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>'></asp:Label><br />
<span style="font-weight:bold; color:Blue; vertical-align:text-top">Comments:</span><br />
<asp:Label ID="CommentsLabel" runat="server" Text='<%# Bind("Comments") %>' Width="600px"></asp:Label><br />
<asp:PlaceHolder ID="RegularPlaceHolder" runat="server">
<asp:Label ID="PrintAvailableTextLabel" runat="server" Text="Print Available:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:HiddenField ID="HiddenField1" runat="server" value = '<%# Bind("PrintAvail") %>'/>
<asp:Label ID="PrintAvailLabel" runat="server"></asp:Label><br />
<asp:Label ID="NoteCardAvailableTextLabel" runat="server" Text="Note Card Available:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:HiddenField ID="HiddenField2" runat="server" value = '<%# Bind("NotecardAvail") %>' />
<asp:Label ID="NotecardAvailLabel" runat="server" ></asp:Label><br />
<asp:Label ID="SizeTextLabel" runat="server" Text="Size:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:Label ID="SizeLabel" runat="server" Text='<%# Bind("Size") %>'></asp:Label><br />
<asp:Label ID="ValueTextLabel" runat="server" Text="Value" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:Label ID="ValueLabel" runat="server" Text='<%# Bind("Value") %>'></asp:Label><br />
</asp:PlaceHolder>
<asp:PlaceHolder ID="PrintValuePlaceHolder" runat="server">
<asp:Label ID="PrintValueTextLabel" runat="server" Text="Print Value:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:Label ID="PrintValueLabel" runat="server" Text='<%# Bind("printValue") %>'></asp:Label><br />
</asp:PlaceHolder>
<asp:PlaceHolder ID="PrintSizePlaceHolder" runat="server">
<asp:Label ID="PrintSizeTextLabel" runat="server" Text="Print Size:" Font-Bold="true" ForeColor="Blue"></asp:Label>
<asp:Label ID="PrintSizeLabel" runat="server" Text='<%# Bind("printSize") %>'></asp:Label><br />
</asp:PlaceHolder>
</ItemTemplate>
</asp:FormView>
AND...
If Request.QueryString("ptype") = 2 Then
CType(FormView1.FindControl("RegularPlaceHolder"), PlaceHolder).Visible = False
'CType(FormView1.FindControl("PrintAvailLabel"), Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("NotecardAvailLabel") , Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("SizeLabel"), Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("ValueLabel"), Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("PrintAvailableTextLa bel"), Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("NoteCardAvailableTex tLabel"), Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("SizeTextLabel"), Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("ValueTextLabel"), Label).Style("visibility") = "hidden"
Else
CType(FormView1.FindControl("PrintSizePlaceHolder" ), PlaceHolder).Visible = False
CType(FormView1.FindControl("PrintValuePlaceHolder "), PlaceHolder).Visible = False
'CType(FormView1.FindControl("PrintValueLabel"), Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("PrintSizeLabel"), Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("PrintValueTextLabel" ), Label).Style("visibility") = "hidden"
'CType(FormView1.FindControl("PrintSizeTextLabel") , Label).Style("visibility") = "hidden"
End If
|
|

August 31st, 2007, 08:09 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Rob,
Setting the control's visible property to false should definately eliminate that controls space occupation from the page as it results in no HTML being rendered for that control. Setting display:none should as well. Usually this problem occurs when the visibility:hidden style is used. This just makes it invisible, but it still takes up the same page real estate.
Using the placeholder to remove a block of controls certainly makes it easier but shouldn't have a different result, unless there is some other styling issue affecting the outcome.
To learn about the page life cycle, try this:
http://www.google.com/search?q=asp.net+life+cycle
-Peter
|
|
 |