Control Visibility

Last post 04-17-2007 1:21 PM by JimAmigo. 4 replies.

Sort Posts:

  • Control Visibility

    04-17-2007, 11:49 AM
    • Member
      581 point Member
    • JimAmigo
    • Member since 01-28-2004, 8:40 AM
    • Posts 252

    I have two controls a hyperlink and label.

    For some reason, I can set the visbility of the hyperlink control onload but it doesn't work for a label control. I get....."label does not exist in the current context".

      if (!Page.IsPostBack)
            {
    
                if (securityid == User.SECURITY_LEVEL_ID_AO_dec)
                {
                    Hyperlink1.Visible = false;
                    Label1.Visible = false
                    //Get ERROR on label visiblity setting
                                    
                }
            }

    Is it because the lable gets rendered elsewhere than the page load? If so where and which event?

    Thanks. 

     

     

    Jim
  • Re: Control Visibility

    04-17-2007, 12:45 PM
    • All-Star
      23,803 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,567
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    There must be some other issue.  see if you can reduce the size of your page and figure out what is going on.  Here is a simple sample that works with label visibility.

    <%

    @ Page Language="C#" %>

    <!

    DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <

    script runat="server">

    protected void Page_Load(object sender, EventArgs e)

    {

    Label1.Visible =

    true;

    }

    </

    script>

    <

    html xmlns="http://www.w3.org/1999/xhtml" >

    <

    head runat="server">

    <title>Untitled Page</title>

    </

    head>

    <

    body>

    <form id="form1" runat="server">

    <div>

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </div>

    </form>

    </

    body>

    </

    html>
    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: Control Visibility

    04-17-2007, 1:04 PM
    • Member
      581 point Member
    • JimAmigo
    • Member since 01-28-2004, 8:40 AM
    • Posts 252

    Ok, I put a label control in a regular page and it worked fine. My guess is... is that the page is a content page with a master page for headers and menus?

    Jim
  • Re: Control Visibility

    04-17-2007, 1:14 PM
    • All-Star
      23,803 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,567
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    you probably need to do a MasterPage.Findcontrol(...

    Take a look at Rick's article on this.

    http://west-wind.com/WebLog/posts/5127.aspx

     

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: Control Visibility

    04-17-2007, 1:21 PM
    Answer
    • Member
      581 point Member
    • JimAmigo
    • Member since 01-28-2004, 8:40 AM
    • Posts 252

    I answered my own question. I had recently copied a file within the same application. It seems the object control reference gets confused between the new, old file and old file code behind.

    Here is where I found the answer... http://simonhibbard.wordpress.com/2007/03/10/aspnet-object-does-not-exist-in-the-current-context-really/

     

    Jim
Page 1 of 1 (5 items)