Issue grabbing div with ID from the MasterPageFile using C# code behind

43 views Asked by At

The aspx file I am using (We can call this page "A") has a MasterPageFile.

In the actual MasterPageFile there is a div. I need to be able to grab this div and use it in the C# code behind page of Page "A".

So here is my question:

How do I grab the div from the MasterPageFile and use it in the C# code behind file of page "A"?

Thank you for your time! :)

1

There are 1 answers

1
Albert D. Kallal On

You are free to grab any control in the master page from child page code

So, say in master page, we have this:

    <div id="DivInMaster" runat="server">


    </div>

So, in the child page, you can do this:

        HtmlGenericControl mydiv = (HtmlGenericControl)Page.Master.FindControl("DivInMaster");

        mydiv.InnerHtml = "<b>Hello world</b>";