Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

what wrong wih this code in Master Page

Posted on 2008-10-10
11
Medium Priority
?
157 Views
Last Modified: 2013-11-07
Hello Experts,
i am trying to declare a public string in a Master Page in asp.net 2.0 C#.
i am getting the following error
Cannot implicitly convert type 'bool' to 'System.Web.UI.WebControls.Panel'
can you please tell me where i am making the mistake. i am attaching the code below
Thanks i appreciate it.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class SideBar : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
       //for panel
 
    public Panel SidebarPanel1
    {
        get
        {
            return Panel1.Visible;
        }
        set
        {
            Panel1.Visible = value;
        }
    }
}

Open in new window

0
Comment
Question by:niceoneishere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22687207
Your declaring your propertie and saying that the return value is going to by a Panel. Change it to
public bool SidebarPanel1
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 22687265
Hello Sir,
ok now my error is gone. but when i try to access the SiderbarPanel1 on the page_load of a aspx page like below, how can i set it visible property to be false. this is what i have in my aspx page
Thanks once again
<%@ Page Language="C#" MasterPageFile="SideBar.master" AutoEventWireup="true" CodeFile="sidebar.aspx.cs" Inherits="Menu_sidebar" Title="Untitled Page" %>
<%@ MasterType VirtualPath="SideBar.master" %>
 
<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
 
          Master.SidebarLabel1 = "";
          Master.SidebarPanel1 // -----what should i do here to make visible = false
           }
 
 
</script>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>

Open in new window

0
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22687360
Panel p = Master.FindControl("SidebarPanel1") as Panel;
if (p != null)
{
m.Visible = false;
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:niceoneishere
ID: 22687400
Hello Sir,
i know how to use the FindControl to acces the control from master page. if you have seen my code in the master page i have something like this for a label1

//for label1
    public string SidebarLabel1
    {
        get
        {
            return Label1.Text;
         }
        set
        {
            Label1.Text = value;
        }
    }

and as you have seen in from my earlier post how  i am accessing SidebarLabel1 in the aspx page. i was hoping to do something along that line sir. is is possible to do that
Thanks once again
0
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22687457
So, your saying that setting the visible propertie to false, it don't hide the panel right?
If so, try yourpanel.Style.Add("display","none")
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 2000 total points
ID: 22688582
Will this do?
Master.SidebarPanel1 = false;
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 22688658
Hello Prairiedog,

bravo !!! it works, one thing i have to ask is , can we this type of coding for other controls like labels, textbox, DDL's etc.
Thanks
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22688684
Labels and textboxes should be ok. But I am not sure for DLL's.
0
 
LVL 1

Author Closing Comment

by:niceoneishere
ID: 31505022
works like a charm Thanks
0
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22688864
For DDL's you can use Style.Add("display","none")
0
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22688879
Sorry last comment, ignore it.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question