Referencing Custom Page Class within a Control

Ask a Question related to ASP.NET General, Design and Development.

  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" <jingyen@emailREMOVEMEuser.net> wrote in message
    news:#4TSSmwRDHA.384@TK2MSFTNGP12.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. Similar Questions and Discussions

    1. Custom Control Class within a class
      I think that this problem might relate to another that I posted. I did a page trace of my custom control and see that OnInit is called every time...
    2. Referencing Page properties from child control
      I'm declaring public properties in a Page's code behind file (not declaratively). I would like to read and assign these from a child control's cs...
    3. Custom control code serialization to class file
      I have a custom control that includes a custom collection. In the collection editor, I add a new item to the collection and that item gets...
    4. Using a component class as a property for a custom control
      Hi, I'm working on a .net application where i'd like to implement the same design-time behavior as used when working with...
    5. Page Load fired 3 times Web user control is embedded in a custom control
      Hi, I have built a custom control that build a table with 3 cells in it. The custom control is designed to add all child controls to cell#2,...
  3. #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" <jingyen@emailREMOVEMEuser.net> wrote in message
    > news:#4TSSmwRDHA.384@TK2MSFTNGP12.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

Posting Permissions

  • You may not post new threads
  • You may 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