Referencing variables on user control pages

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James Glover

    #1

    Referencing variables on user control pages

    I need to be able to reference a variable that is set in the code behind of
    an aspx page in a user control embedded on the page.



    An example:

    The code behind sets a position number; say ,1 to 5. The included user
    control is expecting that variable to know which element to highlight. (The
    first through tenth LI tag in this example.)



    The variable is declared globally prior to the page load on the aspx page
    (i.e. int curNum = 0;) and is updated in subsequent functions depending on
    the user's action. Any idea of how to pass this ID to an acsx page? Thanks
    to all replies given.



  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Referencing variables on user control pages

    James,

    Why not just create a property on the page that exposes this id. Then,
    from inside the user control, you can cast the return value of the Parent
    property to the page type (or an interface that indicates it is a host for
    that control), and then get the property value.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "James Glover" <echo56@gmail.c om> wrote in message
    news:ud3UaiocFH A.2440@TK2MSFTN GP10.phx.gbl...[color=blue]
    >I need to be able to reference a variable that is set in the code behind of
    >an aspx page in a user control embedded on the page.
    >
    >
    >
    > An example:
    >
    > The code behind sets a position number; say ,1 to 5. The included user
    > control is expecting that variable to know which element to highlight.
    > (The first through tenth LI tag in this example.)
    >
    >
    >
    > The variable is declared globally prior to the page load on the aspx page
    > (i.e. int curNum = 0;) and is updated in subsequent functions depending on
    > the user's action. Any idea of how to pass this ID to an acsx page? Thanks
    > to all replies given.
    >
    >
    >[/color]


    Comment

    Working...