User Control needs to refer to Page

Discussion in 'ASP .Net Web Controls' started by Joe Fallon, Feb 12, 2004.

  1. Joe Fallon

    Joe Fallon Guest

    I have a user control which can appear on many pages.
    The control needs to know which page it is on so it can render itself
    correctly.
    What is the best way for the control to find out what page is being
    requested?
    Code snippet would be great.

    Thanks!
    --
    Joe Fallon
     
    Joe Fallon, Feb 12, 2004
    #1
    1. Advertising

  2. Joe Fallon

    Raterus Guest

    You could set a property of the usercontrol on the calling page.

    <my:usercontrol runat="server" pageimon="blah.aspx" />

    "Joe Fallon" <> wrote in message
    news:u$...
    > I have a user control which can appear on many pages.
    > The control needs to know which page it is on so it can render itself
    > correctly.
    > What is the best way for the control to find out what page is being
    > requested?
    > Code snippet would be great.
    >
    > Thanks!
    > --
    > Joe Fallon
    >
    >
    >
    >
    >
     
    Raterus, Feb 12, 2004
    #2
    1. Advertising

  3. Joe Fallon

    Felbrigg Guest

    Hey man try this, it's been givin me good vibes for weeks.

    string pagename = this.Page.Request.CurrentExecutionFilePath;

    int pos = pagename.LastIndexOf("/");

    pagename = pagename.Substring(pos+1,pagename.Length - pos - 1);





    "Raterus" <raterus@localhost> wrote in message
    news:...
    > You could set a property of the usercontrol on the calling page.
    >
    > <my:usercontrol runat="server" pageimon="blah.aspx" />
    >
    > "Joe Fallon" <> wrote in message
    > news:u$...
    > > I have a user control which can appear on many pages.
    > > The control needs to know which page it is on so it can render itself
    > > correctly.
    > > What is the best way for the control to find out what page is being
    > > requested?
    > > Code snippet would be great.
    > >
    > > Thanks!
    > > --
    > > Joe Fallon
    > >
    > >
    > >
    > >
    > >

    >
    >
     
    Felbrigg, Feb 12, 2004
    #3
  4. You could either refer to the current context (I think "this" will get you
    access to the context in a UC). Or you could pass a reference to the parent
    page when the control is created so that you have direct access.

    A better way might be to define methods and properties for the usercontrol
    and define the state using attribute on the HTML tags. This way the control
    does not need to know what page it is one, but rather just needs to know its
    state. What happens if you add a new page that requires the usercontrol, do
    you always want to update the control, or just pass in parameters?

    "Joe Fallon" <> wrote in message
    news:u$...
    > I have a user control which can appear on many pages.
    > The control needs to know which page it is on so it can render itself
    > correctly.
    > What is the best way for the control to find out what page is being
    > requested?
    > Code snippet would be great.
    >
    > Thanks!
    > --
    > Joe Fallon
    >
    >
    >
    >
    >
     
    Peter Rilling, Feb 12, 2004
    #4
  5. Joe Fallon

    Dan Guest

    Or even simpler:

    Dim pagename As String =
    System.IO.Path.GetFileName(Page.Request.CurrentExecutionFilePath))


    "Felbrigg" <> wrote in message
    news:...
    > Hey man try this, it's been givin me good vibes for weeks.
    >
    > string pagename = this.Page.Request.CurrentExecutionFilePath;
    >
    > int pos = pagename.LastIndexOf("/");
    >
    > pagename = pagename.Substring(pos+1,pagename.Length - pos - 1);
    >
    >
    >
    >
    >
    > "Raterus" <raterus@localhost> wrote in message
    > news:...
    > > You could set a property of the usercontrol on the calling page.
    > >
    > > <my:usercontrol runat="server" pageimon="blah.aspx" />
    > >
    > > "Joe Fallon" <> wrote in message
    > > news:u$...
    > > > I have a user control which can appear on many pages.
    > > > The control needs to know which page it is on so it can render itself
    > > > correctly.
    > > > What is the best way for the control to find out what page is being
    > > > requested?
    > > > Code snippet would be great.
    > > >
    > > > Thanks!
    > > > --
    > > > Joe Fallon
    > > >
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Dan, Feb 12, 2004
    #5
  6. Joe Fallon

    Joe Fallon Guest

    Lots of good ideas.
    Thanks!
    --
    Joe Fallon


    "Dan" <> wrote in message
    news:...
    > Or even simpler:
    >
    > Dim pagename As String =
    > System.IO.Path.GetFileName(Page.Request.CurrentExecutionFilePath))
    >
    >
    > "Felbrigg" <> wrote in message
    > news:...
    > > Hey man try this, it's been givin me good vibes for weeks.
    > >
    > > string pagename = this.Page.Request.CurrentExecutionFilePath;
    > >
    > > int pos = pagename.LastIndexOf("/");
    > >
    > > pagename = pagename.Substring(pos+1,pagename.Length - pos - 1);
    > >
    > >
    > >
    > >
    > >
    > > "Raterus" <raterus@localhost> wrote in message
    > > news:...
    > > > You could set a property of the usercontrol on the calling page.
    > > >
    > > > <my:usercontrol runat="server" pageimon="blah.aspx" />
    > > >
    > > > "Joe Fallon" <> wrote in message
    > > > news:u$...
    > > > > I have a user control which can appear on many pages.
    > > > > The control needs to know which page it is on so it can render

    itself
    > > > > correctly.
    > > > > What is the best way for the control to find out what page is being
    > > > > requested?
    > > > > Code snippet would be great.
    > > > >
    > > > > Thanks!
    > > > > --
    > > > > Joe Fallon
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Joe Fallon, Feb 12, 2004
    #6
    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. Mike Hnatt
    Replies:
    6
    Views:
    495
    Mike Hnatt
    Oct 23, 2003
  2. Joe Fallon

    User Control needs to refer to Page

    Joe Fallon, Feb 12, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    2,373
    Joe Fallon
    Feb 12, 2004
  3. news_server.nc.rr.com

    How do I refer to data from nested web user control?

    news_server.nc.rr.com, May 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    602
    news_server.nc.rr.com
    May 20, 2005
  4. Jerry Qu
    Replies:
    1
    Views:
    529
    lee atkinson
    Feb 20, 2009
  5. Joe Fallon

    User Control needs to refer to Page

    Joe Fallon, Feb 12, 2004, in forum: ASP .Net Building Controls
    Replies:
    5
    Views:
    132
    Joe Fallon
    Feb 12, 2004
Loading...

Share This Page