0

How to use a method that is in one of my pages from the masterpage ?

I have a method called Clean ( ) on my page Register, but I want to run it from the masterpage , you can instantiate a class page ?

2 Answers2

0

You could try to cast the current page to the type Register, if that cast succeeds you're there:

var register = this.Page as Register;
if(register != null)
{
    register.Clean();
}

However, normally it is nnot od best practice because a master is typically used for multiple pages. So why do you want to hardwire this master to a specific page?

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • on page master have a ddl , when entering the selectindexchange the value of a changing Session [ ""] , then changes to all pages and all fields would clean on page found ... sorry for my english (i'm colombian) – Alejandro Morales López Apr 15 '15 at 21:10
  • use your solution but does not recognize me page.. – Alejandro Morales López Apr 15 '15 at 21:11
  • @AlejandroMoralesLópez: so what is the type of the current page in the `SelectedIndexChangedEvent` of the `DropDownList`? Have you used the debugger? Just inspect the `Page` property of the `MasterPage`. – Tim Schmelter Apr 15 '15 at 21:44
-2

Interacting with the Content Page from the Master Page (C#)
http://www.asp.net/web-forms/overview/older-versions-getting-started/master-pages/interacting-with-the-content-page-from-the-master-page-cs

Interacting with the Master Page from the Content Page (C#)
http://www.asp.net/web-forms/overview/older-versions-getting-started/master-pages/interacting-with-the-master-page-from-the-content-page-cs

How to: Reference ASP.NET Master Page Content
https://msdn.microsoft.com/en-us/library/xxwa0ff0(v=vs.140).aspx

Working with ASP.NET Master Pages Programmatically https://msdn.microsoft.com/en-us/library/c8y19k6h(v=vs.140).aspx

Valentin Petkov
  • 1,570
  • 18
  • 23
  • You should provide descriptions of how to do these things, rather than just links. – mason Apr 15 '15 at 20:57
  • Everything is there! – Valentin Petkov Apr 15 '15 at 21:01
  • No, everything is *not there*. You need to have the content in your answer itself. A link is not sufficient. The URL's for those pages could change. Their site could go down, temporarily or permanently. – mason Apr 15 '15 at 21:02