accessing aspx object from ascx pages and vise verce?

Discussion in 'ASP .Net Building Controls' started by rom, Nov 22, 2004.

  1. rom

    rom Guest

    Is there a better way of doing it, except from using the
    session variables?

    Thanks!
    rom, Nov 22, 2004
    #1
    1. Advertising

  2. "rom" <> wrote in message
    news:7b2901c4d073$6fca4580$...
    > Is there a better way of doing it, except from using the
    > session variables?


    Depends on what you're asking. What sort of "object" are you referring to?

    Keep in mind that both the page and user control are objects of classes. You
    can add public properties and events to each. For instance, this allows the
    page to pass information to a user control and to subscribe to any events
    the user control raises.

    John Saunders
    John Saunders, Nov 22, 2004
    #2
    1. Advertising

  3. rom

    rom Guest

    Thanks for the quick response. I'm asking, for example,
    about reading the selectedvalue of a dropdownlist that
    exists in the aspx page from it's ascx page....

    Thanks!

    >-----Original Message-----
    >"rom" <> wrote in message
    >news:7b2901c4d073$6fca4580$...
    >> Is there a better way of doing it, except from using the
    >> session variables?

    >
    >Depends on what you're asking. What sort of "object" are

    you referring to?
    >
    >Keep in mind that both the page and user control are

    objects of classes. You
    >can add public properties and events to each. For

    instance, this allows the
    >page to pass information to a user control and to

    subscribe to any events
    >the user control raises.
    >
    >John Saunders
    >
    >
    >.
    >
    rom, Nov 22, 2004
    #3
  4. "rom" <> wrote in message
    news:8f9201c4d092$3bf19ff0$...
    > Thanks for the quick response. I'm asking, for example,
    > about reading the selectedvalue of a dropdownlist that
    > exists in the aspx page from it's ascx page....


    Again, you're talking objects now. :)

    How would you handle this if there were some integer inside of object A
    wihch you wanted to be able to access from object B? With a property!

    However, your user controls are inside of your page. The usual way to handle
    this sort of thing is for the container to set the properties of the
    contained objects, and not the other way around. For instance, you could add
    a ListSelectedIndex property to your user control, and your page could set
    it in Page_Load or in the DataBinding event of the user control. If the user
    control wanted to be able to change the SelectedIndex, it should expose a
    public event. The page could listen for that event and set the SelectedIndex
    accordingly. The event arguments would have to pass the new index.

    Note how this isolates the page and the control from each other. The page
    doesn't have to know _why_ the user control wants the SelectedIndex changed,
    and the user control doesn't know anything at all about the DropDownList.
    You could even change it to use a different control, and the user control
    wouldn't care at all.


    John Saunders
    John Saunders, Nov 23, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Milsnips
    Replies:
    4
    Views:
    2,119
    Anders Norås
    Nov 19, 2004
  2. rom
    Replies:
    1
    Views:
    857
    Anders Norås
    Nov 22, 2004
  3. Luis Esteban Valencia
    Replies:
    1
    Views:
    516
    Curt_C [MVP]
    Jan 6, 2005
  4. Garth17
    Replies:
    3
    Views:
    3,010
    Brock Allen
    Mar 18, 2005
  5. RadioSignal

    passing variables from .aspx.cs code pages to .aspx pages

    RadioSignal, Sep 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    7
    Views:
    2,185
    Mirronelli
    Oct 22, 2005
Loading...

Share This Page