Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 29th, 2007, 08:58 PM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default 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


Reply With Quote
  #2 (permalink)  
Old August 29th, 2007, 09:25 PM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

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

Reply With Quote
  #3 (permalink)  
Old August 31st, 2007, 08:09 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to hide control and show no space? rsearing ASP.NET 2.0 Basics 3 March 18th, 2007 09:39 AM
Hide a Row in a FormView Control frosty ASP.NET 2.0 Basics 5 July 14th, 2006 03:07 PM
Looks like a space but it isn't. rstelma SQL Server 2000 3 September 7th, 2005 07:17 PM
space crmpicco Javascript How-To 1 February 7th, 2005 01:26 PM
how to replace space with ; mp218 Access VBA 4 August 5th, 2003 07:32 AM



All times are GMT -4. The time now is 06:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.