How do I use the public function I clarified in Master Page, and use it in other web forms?

Last post 03-21-2008 10:38 PM by canalso. 4 replies.

Sort Posts:

  • How do I use the public function I clarified in Master Page, and use it in other web forms?

    03-19-2008, 3:20 AM
    • Member
      302 point Member
    • canalso
    • Member since 03-19-2008, 12:49 AM
    • Posts 226

    I have written a public function in Master Page's Code File, and would like to use it in other web form while i would like to get the label out of the function return.

    Mark up:

    • I have placed the ClassName ="MasterPage" in Master Page's <%@  Master.. ClassName="MasterPage" %>
    • I have placed <%@ MasterType TypeName="Site.Master" in Web form used (or should i use VirtualPath instead?)

    Error :

    • BC30456: 'RetrieveLanguageText' is not a member of 'System.Web.UI.MasterPage'.

    Main.Master.vb (Site.Master's Code File)

    Public Function RetrieveLanguageText(ByVal strlangfilename As String, ByVal strlangsession As String)Dim LangSetting As XmlLang01 = New XmlLang01

    LangSetting.XmlLang(strlangfilename, strlangsession)

    lblgreeting.Text = LangSetting.GetString("Greeting")

    Return LangSetting

    End Function

    Webform's Code File

    Protected WithEvents lblgreeting As System.Web.UI.WebControls.Label

    Dim m As MasterPage = CType(Page.Master, MasterPage)

    lblgreeting.Text = m.RetrieveLanguageText("languageLA.xml", LanguageValue)

    Web form

    <asp:Label ID="lblgreeting" runat="server" />

    . . : : LarnVok : : . .
  • Re: How do I use the public function I clarified in Master Page, and use it in other web forms?

    03-19-2008, 3:55 AM
    • Star
      8,559 point Star
    • siva_sm
    • Member since 12-20-2007, 11:03 AM
    • Posts 1,256
    There is already a class named MasterPage in ASP.NET, the parent class for master pages. Give some other name for ClassName in the master page and use the same in CType and try.
    Mark replies as answers if they helped you solve the problem.
  • Re: How do I use the public function I clarified in Master Page, and use it in other web forms?

    03-19-2008, 4:04 AM
    • Member
      302 point Member
    • canalso
    • Member since 03-19-2008, 12:49 AM
    • Posts 226

    I have changed to MasterExample instead of MasterPage, i received this error

    Error:

    • BC30002: Type 'MasterExample' is not defined.

    However, any suggestions on using the public function from the master page is good.

    . . : : LarnVok : : . .
  • Re: How do I use the public function I clarified in Master Page, and use it in other web forms?

    03-21-2008, 2:45 AM

    Hi,

    canalso:
    I have placed <%@ MasterType TypeName="Site.Master" in Web form used (or should i use VirtualPath instead?)

    Do you have a try to use the VirtualPath instead? I test it by using VirtualPath, it works fine on my local.

     Because the VirtualPath attribute supports only a single master page. but TypeName is used to specify the name of the base class which the master page inherits from.

    The more about the master page and the details, you can refer this article: http://www.odetocode.com/Articles/450.aspx 

    Hope it helps.

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: How do I use the public function I clarified in Master Page, and use it in other web forms?

    03-21-2008, 10:38 PM
    Answer
    • Member
      302 point Member
    • canalso
    • Member since 03-19-2008, 12:49 AM
    • Posts 226

    I used global assembly which suggested by other contributor's post on the other forum discussion to fix it already

     

    Wink

      

    . . : : LarnVok : : . .
Page 1 of 1 (5 items)