Professional Web Applications Themes

Referencing Custom Page Class within a Control - ASP.NET General

C# code. MyPageClass myPage = ( MyPageClass ) this.Page; myPage now is the instance of MyPageClass the control on. bill "Cheung, Jeffrey Jing-Yen" <jingyenemailREMOVEMEuser.net> wrote in message news:#4TSSmwRDHA.384TK2MSFTNGP12.phx.gbl... > How do I obtain a reference to a Custom Page object written that > inherits System.Web.UI.Page when the control exists on that custom page? > Referencing Me.Page doesn't work as it goes directly to the base class > System.Web.UI.Page. > > Ex: (please mind the word wrap) > > This is my custom page class: > > Public Class MyPageClass > Inherits CWebPage > ' My protected instance variable that I ...

  1. #1

    Default Re: Referencing Custom Page Class within a Control

    C# code.


    MyPageClass myPage = ( MyPageClass ) this.Page;

    myPage now is the instance of MyPageClass the control on.

    bill



    "Cheung, Jeffrey Jing-Yen" <jingyenemailREMOVEMEuser.net> wrote in message
    news:#4TSSmwRDHA.384TK2MSFTNGP12.phx.gbl...
    > How do I obtain a reference to a Custom Page object written that
    > inherits System.Web.UI.Page when the control exists on that custom page?
    > Referencing Me.Page doesn't work as it goes directly to the base class
    > System.Web.UI.Page.
    >
    > Ex: (please mind the word wrap)
    >
    > This is my custom page class:
    >
    > Public Class MyPageClass
    > Inherits CWebPage
    > ' My protected instance variable that I want to access from the control
    > Protected m_myvar As Boolean
    > '... irrelevant overloaded methods here
    > '...
    > End Class
    >
    >
    > On the presentation layer, I have a control that is correctly registered
    > via the Register directive
    >
    > <% Register TagPrefix="userControl" TagName="MyControl"
    > Src="..path/to/my/control.ascx" %>
    >
    > In my control codebehind, I need to obtain a reference to the Custom
    > Page class ->
    >
    >
    > Public Class MyControl
    > Inherits WebControl
    > Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > ' I need to obtain a reference to the custom page object to get my
    > protected instance variable value.
    > End Sub
    > End Class
    >
    >
    > Thanks in advance,
    >
    > Jeff Cheung
    >

    William F. Robertson, Jr. Guest

  2. #2

    Default Re: Referencing Custom Page Class within a Control

    William,

    Thanks so much!

    For reference, here's the VB.NET equivalent:
    ' Begin Code Snippet
    Dim MyPageClass As MyPageClass

    MyPageClass = Me.Page
    ' End Code Snippet

    Jeff Cheung


    William F. Robertson, Jr. wrote:
    > C# code.
    >
    >
    > MyPageClass myPage = ( MyPageClass ) this.Page;
    >
    > myPage now is the instance of MyPageClass the control on.
    >
    > bill
    >
    >
    >
    > "Cheung, Jeffrey Jing-Yen" <jingyenemailREMOVEMEuser.net> wrote in message
    > news:#4TSSmwRDHA.384TK2MSFTNGP12.phx.gbl...
    >
    >>How do I obtain a reference to a Custom Page object written that
    >>inherits System.Web.UI.Page when the control exists on that custom page?
    >> Referencing Me.Page doesn't work as it goes directly to the base class
    >>System.Web.UI.Page.
    >>
    >>Ex: (please mind the word wrap)
    >>
    >>This is my custom page class:
    >>
    >>Public Class MyPageClass
    >>Inherits CWebPage
    >>' My protected instance variable that I want to access from the control
    >>Protected m_myvar As Boolean
    >>'... irrelevant overloaded methods here
    >>'...
    >>End Class
    >>
    >>
    >>On the presentation layer, I have a control that is correctly registered
    >>via the Register directive
    >>
    >><% Register TagPrefix="userControl" TagName="MyControl"
    >>Src="..path/to/my/control.ascx" %>
    >>
    >>In my control codebehind, I need to obtain a reference to the Custom
    >>Page class ->
    >>
    >>
    >>Public Class MyControl
    >>Inherits WebControl
    >>Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
    >>System.EventArgs) Handles MyBase.Load
    >>' I need to obtain a reference to the custom page object to get my
    >>protected instance variable value.
    >>End Sub
    >>End Class
    >>
    >>
    >>Thanks in advance,
    >>
    >>Jeff Cheung
    >>
    >
    >
    >
    Cheung, Jeffrey Jing-Yen Guest

Similar Threads

  1. Custom Control Class within a class
    By ryan.d.rembaum@kp.org in forum ASP.NET Building Controls
    Replies: 0
    Last Post: February 7th, 08:48 PM
  2. Referencing Page properties from child control
    By in forum ASP.NET Building Controls
    Replies: 5
    Last Post: August 8th, 11:57 PM
  3. Custom control code serialization to class file
    By Dale in forum ASP.NET Building Controls
    Replies: 6
    Last Post: August 2nd, 06:41 AM
  4. Using a component class as a property for a custom control
    By Chris in forum ASP.NET Building Controls
    Replies: 0
    Last Post: November 11th, 08:25 AM
  5. Page Load fired 3 times Web user control is embedded in a custom control
    By Thomas Ekegren in forum ASP.NET Building Controls
    Replies: 0
    Last Post: September 3rd, 05:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139