Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > User Control needs to refer to Page

Reply
Thread Tools

User Control needs to refer to Page

 
 
Joe Fallon
Guest
Posts: n/a
 
      02-12-2004
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





 
Reply With Quote
 
 
 
 
Raterus
Guest
Posts: n/a
 
      02-12-2004
You could set a property of the usercontrol on the calling page.

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

"Joe Fallon" <(E-Mail Removed)> wrote in message
news:u$(E-Mail Removed)...
> 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
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Felbrigg
Guest
Posts: n/a
 
      02-12-2004
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:(E-Mail Removed)...
> You could set a property of the usercontrol on the calling page.
>
> <my:usercontrol runat="server" pageimon="blah.aspx" />
>
> "Joe Fallon" <(E-Mail Removed)> wrote in message
> news:u$(E-Mail Removed)...
> > 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
> >
> >
> >
> >
> >

>
>



 
Reply With Quote
 
Peter Rilling
Guest
Posts: n/a
 
      02-12-2004
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" <(E-Mail Removed)> wrote in message
news:u$(E-Mail Removed)...
> 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
>
>
>
>
>



 
Reply With Quote
 
Dan
Guest
Posts: n/a
 
      02-12-2004
Or even simpler:

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


"Felbrigg" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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:(E-Mail Removed)...
> > You could set a property of the usercontrol on the calling page.
> >
> > <my:usercontrol runat="server" pageimon="blah.aspx" />
> >
> > "Joe Fallon" <(E-Mail Removed)> wrote in message
> > news:u$(E-Mail Removed)...
> > > 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
> > >
> > >
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Joe Fallon
Guest
Posts: n/a
 
      02-12-2004
Lots of good ideas.
Thanks!
--
Joe Fallon


"Dan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Or even simpler:
>
> Dim pagename As String =
> System.IO.Path.GetFileName(Page.Request.CurrentExe cutionFilePath))
>
>
> "Felbrigg" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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:(E-Mail Removed)...
> > > You could set a property of the usercontrol on the calling page.
> > >
> > > <my:usercontrol runat="server" pageimon="blah.aspx" />
> > >
> > > "Joe Fallon" <(E-Mail Removed)> wrote in message
> > > news:u$(E-Mail Removed)...
> > > > 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
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to refer a control in the host page from a user control if the host page using masterpage Jerry Qu ASP .Net 1 02-20-2009 07:41 PM
How do I refer to data from nested web user control? news_server.nc.rr.com ASP .Net 0 05-19-2005 11:25 PM
User Control needs to refer to Page Joe Fallon ASP .Net 5 02-12-2004 03:28 PM
User Control needs to refer to Page Joe Fallon ASP .Net Building Controls 5 02-12-2004 03:28 PM
How do you refer to a textbox that is located in a User Control? Mike Hnatt ASP .Net 6 10-23-2003 04:41 AM



Advertisments