Usercontrol interacting with it's parent page?

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

  1. #1

    Default Usercontrol interacting with it's parent page?

    Hi all,

    Is it possible for a usercontrol to call a public method of a page it is
    contained within? If so, how?

    Regards
    John.


    John Guest

  2. Similar Questions and Discussions

    1. Restrict page access to parent page only (not by permissions)
      I wish to restrict access of a pop-up page to parent page only. i.e. - if a request for "popup.cfm" comes from anywhere except "launch.cfm" then...
    2. dynamic userControl can't be accessed during page load
      I have a userControl that I create based on how many rows I retrieve in a dataset. I add the control to my page but can't access it during the...
    3. Getting data from a usercontrol before containing page ends its page load
      How do I load a user control in a web form first, so that the web form's page_load acts according to events on the user control? In my code...
    4. Abstract Base Page / UserControl
      Our current solution has a number of ASP.NET pages with very similar functionality. We would like to move the common functions into a base class...
    5. Help: Usercontrol - different behaviors based on parent
      I have a usercontrol that is basically a webapp-wide menu (dropdownlists, etc...) Is there a way I can program a certain dropdownlist in the uc...
  3. #2

    Default Re: Usercontrol interacting with it's parent page?

    Hi

    Since your page is a class too. In your user control you can create an
    instance of it and then call its method.

    But i also doubt on this being the best way and only way to do what u want
    to do.

    HTH


    "John" <a@b.com> wrote in message
    news:OWS39NBQDHA.1336@TK2MSFTNGP11.phx.gbl...
    > Hi all,
    >
    > Is it possible for a usercontrol to call a public method of a page it is
    > contained within? If so, how?
    >
    > Regards
    > John.
    >
    >

    Vaibhav Guest

  4. #3

    Default Re: Usercontrol interacting with it's parent page?

    Every Control has a property named "Page". This gives you the refrence to
    the containing page object. YOu can call public methods through this
    refrence.

    --
    Naveen K Kohli
    [url]http://www.netomatix.com[/url]
    "John" <a@b.com> wrote in message
    news:OWS39NBQDHA.1336@TK2MSFTNGP11.phx.gbl...
    > Hi all,
    >
    > Is it possible for a usercontrol to call a public method of a page it is
    > contained within? If so, how?
    >
    > Regards
    > John.
    >
    >

    Naveen K Kohli Guest

  5. #4

    Default Re: Usercontrol interacting with it's parent page?

    Mark the method public static and pass any necessary state information as
    arguments.

    ~PJ

    "John" <a@b.com> wrote in message
    news:OWS39NBQDHA.1336@TK2MSFTNGP11.phx.gbl...
    > Hi all,
    >
    > Is it possible for a usercontrol to call a public method of a page it is
    > contained within? If so, how?
    >
    > Regards
    > John.
    >
    >

    PJ Guest

  6. #5

    Default Usercontrol interacting with it's parent page?

    Yes, but you need to redefine the Page property from
    within the user control to be of the type containing the
    public method you want to access:

    public class MyUC
    inherits UserControl

    protected readonly shadows property Page as MyPage
    get
    return ctype(mybase.Page, MyPage)
    end get
    end property

    '... rest of class

    'call method in containing page
    Page.Method()

    end class


    >-----Original Message-----
    >Hi all,
    >
    >Is it possible for a usercontrol to call a public method
    of a page it is
    >contained within? If so, how?
    >
    >Regards
    >John.
    >
    >
    >.
    >
    Joe Agster Guest

  7. #6

    Lightbulb Re: Usercontrol interacting with it's parent page?

    On WebUserControl :-

    Page page = HttpContext.Current.Handler as Page;
    TextBox1.Text=(page.FindControl("") as TextBox).text.ToString();
    Unregistered 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