1

How to call master page method in content page but the content page is not inheritted from the master page. what i have to do to call the master page method in content page

this is my Operation master page method public void RedirectPage(string url) {
ifrmMstr.Attributes.Add("src", url);
}

And this is my content page and i am calling the function like this in the page load

Operation master = new Operation(); master.rpage("../Default.aspx");

K M
  • 11
  • 5
  • What is contained in the method? Is it some sort of utility function? If it is, it is best to extract it out of master page and place it in reusable library as a static method or a similar approach. – murtazat May 06 '15 at 05:12
  • In that method i am changing the source of the iframe. – K M May 06 '15 at 05:15
  • Are you doing it from server side? Can you post asp.net markup plus server side code or any javascript that changes the source of iframe? – murtazat May 06 '15 at 05:17
  • this is my Master method – K M May 06 '15 at 05:20
  • public void RedirectPage(string url) { ifrmMstr.Attributes.Add("src", url); } – K M May 06 '15 at 05:22
  • Please post code of the method that changes iframe source? Does it stay in master page? – murtazat May 06 '15 at 05:22
  • i am calling the method like this – K M May 06 '15 at 05:23
  • Operation master = new Operation(); master .RedirectPage("../Default.aspx"); – K M May 06 '15 at 05:23
  • I think you are trying to create an instance of master page and then use its public method which is not a good asp.net practice. Is it possible for you to create a static method outside your master page and grab "ifrmMstr" in such static method? Else - you may also change entire approach of redirection and do a client side redirect only. You should be able to grab iframe element on button click and change the iframe source at client side only without doing a server round-trip. – murtazat May 06 '15 at 05:29
  • I tried with the static method also but in that case when i find the iframe that is getting null reference value so i am not able to do please help me out from this – K M May 06 '15 at 05:36

2 Answers2

1

Does this help?

https://www.google.co.nz/#q=expose+control+from+master+page+to+content+page

"....To access the Master Page's methods or properties from a content page, reference the Master Page through the Page.Master property. This property returns an object of type MasterPage, so you'll need to explicitly cast it to the appropriate type before calling its methods or referencing its properties. Alternatively, you can set the @MasterType directive, which adds a property to the auto-generated ASP.NET code-behind class code named Master that is a strongly-typed reference to the specified Master Page...."

This will also be useful

How to control elements on a asp.net master page from child page

Community
  • 1
  • 1
murtazat
  • 399
  • 3
  • 12
  • This will work only if the child page is inherited from the master page. But in my situation i am not using the master page for the child page – K M May 06 '15 at 05:49
0

You can change the Master page frame's source from content page by calling a master page's JavaScript function and doing it client side.

Add something like this in your content page method (vb.net):

    Dim frameSourceMethod As String = String.Format("YourMethod('{0}');",frameSourcePath)
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "displdcccdsse4errnfokf", frameSourceMethod , True)