Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a master page's variable from a user control

Status
Not open for further replies.

glyns

Programmer
Dec 15, 2008
125
0
0
GB
This is my master page
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterPages_mymasterpage : System.Web.UI.MasterPage
{
  protected void Page_Load(object sender, EventArgs e)
  {
  }

  public string xyz
  {
    get { return "xyz"; }
  }
}

The code behind my default.aspx page is
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
      string a = "";
      a = ((MasterPages_mymasterpage)this.Master).xyz;

The reference "MasterPages_mymasterpage" keeps appearing and disappearing out of the autocomplete context dropdown and has now stopped appearing all together.

I've tried adding
MasterPageFile = "~/MasterPages/mymasterpage.master";
to the c# and
<%@ MasterType VirtualPath="~/MasterPages/mymasterpage.master"%>
to the aspx file, but neither has any effect
Anybody have any ideas why MasterPages_mymasterpage keeps dropping out or knows of some better way to reference a variable in a master page from a sub page?

Also, I need it in a user control eventually, should the code that fixes default.aspx be used for mycontrol.ascx??


Thanks
 
This forum is for classic ASP. You should repost here: forum855
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top