views:

928

answers:

2

I have a menu of report links in my master page. I need to append an ID to the end of each whenever the user changes a value on the child page. What's a good way to accomplish this?

UPDATE: I should have mentioned that the child update is happening inside an UpdatePanel, meaning the master page is not reloaded when the change happens.

+2  A: 

A MasterPage is really a child control of the page which it controls. You can control a MasterPage like any other control on your page (almost). All you need to do is get a reference to it.

You add a property to the code of your MasterPage, so its code may look something like this:

public partial class _default : System.Web.UI.MasterPage
{
    protected string m_myString = string.Empty;
    public string myString
    {
        get { return m_myString; }
        set { m_myString = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

Then you have to cast the this.Master property to your MasterPage

public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Cast here to get access to your MasterPage
        _default x = (_default)this.Master;
        x.myString = "foo";
    }
}
jrcs3
See the update I just added to the original problem. I would have normally used your method, but the partial page update is complicating things.
gfrizzle
You have 2 choices that I can see.1. Update the IDs using javascript on the client side2. Update the IDs as above and put that area of the MasterPage in a second update panel.
jrcs3
Will an update panel in the master page refresh if a child refreshes? I tried a quick test and it didn't appear to work, but I could have messed something up.
gfrizzle
A: 

In response to your UPDATE:

The updated panel could write the ID to a hidden field and the menu events could look for that hidden fields in Request.Form["fieldName"].

Note that you shouldn't fieldName.Text because ASP.NET does a bad job of returning the right value for fields that have been AJAXed.

jrcs3