Accessing shared properties in a pge

W

WFB

Hi,

In asp.net 1.1, it was easy to add this to the properties of a page (class):

Public Shared ReadOnly Property URL(productId as String) As String
Get
Return AppPath & "/ProductDetails.aspx?productId=" & productId
End Get
End Property

Which I could then access from other pages (which stopped me having to
memorze and hardcode a URL in dozens of pages and user controls). However,
in 2.0 this functionality seems to have dissapeard. Is there any way to get
to this, or a reccomended altenate approach?

Thanks
Joe
 
P

Peter Rilling

Rather than attaching the method to the page, it might make more sense to
create a Utility class and add the method there.
 
B

Bruce Barker

not with the ease.

when you run the wizard, it will create new class file in the appcode dir
that has this static method, and then change the page to inherit from it.
this will be great for your old pages, but a pain when you add new ones.

this comes about because in version 1, all the codebehinds went into 1 dll,
so they could reference each other, in 2.0 they go into seperate dlls (1 per
page), and app_code (1 dll for the dir) is where the shared code is.


-- bruce (sqlwork.com)
 
W

WFB

In general, how are other people handling this (in 1.1 and 2.0)? Just
hardcoding the links?
 
G

Greg Burns

Just add a new class, and mark the property shared.

Sounds like it is not so simply in ASP.NET 2.0 anymore. ?? :(
 
Y

Yunus Emre ALPÖZEN [MCSD.NET]

Implement a singleton pattern class and add this methods to this class, my
advice is.

But anyway, links are external resources therefore can be stored in Resx
file. This would help you integrate your modules/pages with other
applications.

--
HTH

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET
 
W

WFB

Thanks. Do you have an example?

Yunus Emre ALPÖZEN said:
Implement a singleton pattern class and add this methods to this class, my
advice is.

But anyway, links are external resources therefore can be stored in Resx
file. This would help you integrate your modules/pages with other
applications.

--
HTH

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET
 
W

WFB

Sorry - I sent too soon. If possible can you point me to an example of
using the resx file?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top