Master Page , User Control,Content page

 Hi friend ,I have user control at master page, I want to access it's property using content page I have done code but getting problem in deployment.

((ASP.usercontrols_travel_hotel_directory_ascx)Master.FindControl("ucHotel_Directory")).Visible = false;

 

But I am getting following error in deployment project

 Error    137    The type or namespace name 'usercontrols_travel_animation_ascx' does not exist in the namespace 'ASP' (are you missing an assembly reference?)    d:\By Shakti5385\EternalMewar\EternalMewarWeb\User\Travel\Hotels\Grand_Heritage\Fateh_Prakash\photogallery.aspx.cs    58    1    EternalMewarWeb_deploy

Please let me know how to do that.

Thanks


My Blog:NEXT MVP

Today Article

0
shakti5385
7/18/2008 7:19:36 AM
asp.net.config-deploy 12495 articles. 0 followers. Follow

12 Replies
872 Views

Similar Articles

[PageSpeed] 22

Make sure you add a reference to your user control in your page aspx:

<%@ Reference Control="~/UserControls/Controlname.ascx"%>
 

 


If this post was useful to you, please mark it as answer. Thank you!
0
johram
7/18/2008 8:13:29 AM

I have done that but still I am getting error.

you can check my small project demo at http://www.4shared.com/file/55646745/5cd99eb9/Testing.html

It containg only user control, master page and content page

Thanks


My Blog:NEXT MVP

Today Article

0
shakti5385
7/18/2008 8:30:40 AM
any solution
thanks  Crying

My Blog:NEXT MVP

Today Article

0
shakti5385
7/21/2008 5:50:12 AM

Make your control public in the master page, something like:

 

public MycontrolInMaster

{

 get

{

 return this.MyControlName;

}

}

 

Then in the content page, using this.Page.Master and casting it for the MasterPage type, you'll be able to use your control.

0
stealth_pt
7/21/2008 11:18:32 AM

 Im not sure if you fixed this but I have a similar issue:

USING CODE BESIDE! My Master page has an attribute classname="MyMasterClass". In the master page I have a user control with an attribute classname="MyUserControlClass" defined in the .ascx file.

In the master page file I then define a public property to the user control:

 

public MyUserControlClass MyControl
{
   get{return myControlIdOnThePage;}
}
 

In the page that inherits the master page in the "Page_Load" I do:

 

  MyMasterClass mmc = new MyMasterClass();
  mmc.MyControl.Visible = false;
 

This produces the error  "Object reference not set to an instance of an object"....The intelliense recognizes the public control property so I know its there....any ideas?

0
migo
7/22/2008 6:30:59 PM

 I actually made this more better by doing

 

<%@ mastertype virtualpath="~/pathtomasterpages/mymasterpage.Master" %>

  Then in the Page

 

Master.MyUserControl.Visible = false;
  
0
migo
7/22/2008 7:03:57 PM

The problem in your code is that your control is not inicialized. So in your content page what you should do instead is something like this:

 

MyMasterPageType theMaster = (MyMasterPageType)this.Page.Master;

theMaster.MyControl.Visible = false;

 

And then it will work!!! :)

 

Regards...

 

 

0
stealth_pt
7/23/2008 8:45:49 AM

 Thanks but I have not get solution of that problem

any one help me

Thanks


My Blog:NEXT MVP

Today Article

0
shakti5385
7/23/2008 9:28:25 AM

stealth_pt:

The problem in your code is that your control is not inicialized. So in your content page what you should do instead is something like this:

 

MyMasterPageType theMaster = (MyMasterPageType)this.Page.Master;

theMaster.MyControl.Visible = false;

 

And then it will work!!! :)

 

Regards...

 

 

 

 

Please provide me namspace of  MyMasterPageType


My Blog:NEXT MVP

Today Article

0
shakti5385
7/23/2008 9:36:40 AM

 I downloaded the code and got it to work

MasterPage.Master.cs

 

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 MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public WebUserControl WebUserControl
    {
      get { return WebUserControl1; }
    }
}

  Default.aspx.cs

 

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 _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      MasterPage m = (MasterPage)Page.Master;
      m.WebUserControl.Visible = false;
    }
}
  
0
migo
7/23/2008 12:15:14 PM

 thanks but I am getting two error

Error    1    The type 'WebUserControl' is defined in an assembly that is not referenced. You must add a reference to assembly 'App_Web_tfyvlf9y, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.    C:\Documents and Settings\Administrator\Testing\Default.aspx.cs    17    9    C:\...\Testing\
Error    2    'WebUserControl' does not contain a definition for 'Visible'    C:\Documents and Settings\Administrator\Testing\Default.aspx.cs    17    26    C:\...\Testing\
 

 

will u provide me entire code please download it any where


My Blog:NEXT MVP

Today Article

0
shakti5385
7/23/2008 1:47:47 PM

Proabably the problem is that you have the ASPX in one project and the control in other. Just make the reference to that project in the ASPX one.

 

Hope it helps

0
stealth_pt
7/24/2008 9:58:39 AM
Reply: