Accessing method in master page from content page

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

OK, now I'm getting excited. I actually created a master page and added two
content place holders to it. I also added a label which will serve as a sort
of one line help and a little image button beside it to turn off the help.

I wrote a public method in the master page that looks like this:

public void tattle(string as_msg)
{
microhelp.Text = as_msg;
}

Pretty simple. microhelp is that label that I spoke of. How can I run the
tattle method from a content page?
 
Rik,

You can get the MasterPage instance from the Master property on your
page. Once you have that, you should be able to cast that to an instance of
your specific page type, and call the method.

However, I would say that doing this doesn't make sense. If anything,
you should have your master page implement an interface and then cast the
value of Master to that interface.

Hope this helps.
 
Thank you so much Nicholas, but that confused me more than ever. First of
all, I've implemented interfaces in classes in Java, but didn't know that you
could do that for an asp page.

Secondly, I really don't understand what you mean with your instructions.
Could I prevail upon you to give me a couple of lines as an example --- if I
ask, pretty please?
----------------------------------------
Magic is not in the hands of the magician but in the mind of the audience.

Animadverto est verus




Nicholas Paldino said:
Rik,

You can get the MasterPage instance from the Master property on your
page. Once you have that, you should be able to cast that to an instance of
your specific page type, and call the method.

However, I would say that doing this doesn't make sense. If anything,
you should have your master page implement an interface and then cast the
value of Master to that interface.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rik Brooks said:
OK, now I'm getting excited. I actually created a master page and added
two
content place holders to it. I also added a label which will serve as a
sort
of one line help and a little image button beside it to turn off the help.

I wrote a public method in the master page that looks like this:

public void tattle(string as_msg)
{
microhelp.Text = as_msg;
}

Pretty simple. microhelp is that label that I spoke of. How can I run the
tattle method from a content page?

--
 
Rik,

Say tattle is implemented as you have it, in your master page class,
called MyMasterPage. In your page that has the content, you would do
something like this:

<%
((MyMasterPage) this.Master).tattle("hey there");
%>


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rik Brooks said:
Thank you so much Nicholas, but that confused me more than ever. First of
all, I've implemented interfaces in classes in Java, but didn't know that
you
could do that for an asp page.

Secondly, I really don't understand what you mean with your instructions.
Could I prevail upon you to give me a couple of lines as an example --- if
I
ask, pretty please?
----------------------------------------
Magic is not in the hands of the magician but in the mind of the audience.

Animadverto est verus




Nicholas Paldino said:
Rik,

You can get the MasterPage instance from the Master property on your
page. Once you have that, you should be able to cast that to an instance
of
your specific page type, and call the method.

However, I would say that doing this doesn't make sense. If
anything,
you should have your master page implement an interface and then cast the
value of Master to that interface.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rik Brooks said:
OK, now I'm getting excited. I actually created a master page and added
two
content place holders to it. I also added a label which will serve as a
sort
of one line help and a little image button beside it to turn off the
help.

I wrote a public method in the master page that looks like this:

public void tattle(string as_msg)
{
microhelp.Text = as_msg;
}

Pretty simple. microhelp is that label that I spoke of. How can I run
the
tattle method from a content page?

--
----------------------------------------
Magic is not in the hands of the magician but in the mind of the
audience.

Animadverto est verus
 
Thank you so much, Nicholas. This works like a charm and will certainly serve
my purposes.
--
----------------------------------------
Magic is not in the hands of the magician but in the mind of the audience.

Animadverto est verus




Nicholas Paldino said:
Rik,

Say tattle is implemented as you have it, in your master page class,
called MyMasterPage. In your page that has the content, you would do
something like this:

<%
((MyMasterPage) this.Master).tattle("hey there");
%>


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rik Brooks said:
Thank you so much Nicholas, but that confused me more than ever. First of
all, I've implemented interfaces in classes in Java, but didn't know that
you
could do that for an asp page.

Secondly, I really don't understand what you mean with your instructions.
Could I prevail upon you to give me a couple of lines as an example --- if
I
ask, pretty please?
----------------------------------------
Magic is not in the hands of the magician but in the mind of the audience.

Animadverto est verus




Nicholas Paldino said:
Rik,

You can get the MasterPage instance from the Master property on your
page. Once you have that, you should be able to cast that to an instance
of
your specific page type, and call the method.

However, I would say that doing this doesn't make sense. If
anything,
you should have your master page implement an interface and then cast the
value of Master to that interface.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

OK, now I'm getting excited. I actually created a master page and added
two
content place holders to it. I also added a label which will serve as a
sort
of one line help and a little image button beside it to turn off the
help.

I wrote a public method in the master page that looks like this:

public void tattle(string as_msg)
{
microhelp.Text = as_msg;
}

Pretty simple. microhelp is that label that I spoke of. How can I run
the
tattle method from a content page?

--
----------------------------------------
Magic is not in the hands of the magician but in the mind of the
audience.

Animadverto est verus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top