What is the most efficient way to access common fcts on asp.net pages when using user controls?

B

Brent Minder

What is the most efficient way to code asp.net pages when you break your
page up into user controls?

For example: If you have a page with a header (control .ascx), body, and
footer (control .ascx) for a given page and you need to access functions
within a class (bizUtil say) should you declare the bizUtil object on the
header and footer in both the aspx and aspx.vb pages? That's FOUR
references!

This seems bloatful (my new word).

Just wondering,

Brent
 
K

Kikoz

Hi.

Two ways:
You can create a separate class somewhere in your project
with static method(s) that you need if this class does
not need initialization (I'm not sure what "statis"
stands for in VB). Than use it in your user control: (C#)
classNamespace.className.staticMethod(someParameter);

Second:
Create a base class(es) for your user control(s). Derive
this base from System.Web.UI.UserControl. Then place all
methods your "child" controls might need inside of this
base class. Then derive all or some of your user controls
from this base control class and you're done. Just call
those methods right from "child" controls. Very neat,
efficient, hassle free and elegant approach :)

Regards.
 
B

Brent

Thanks so much for the help. I don't have a clue how to do either of these,
but now at least i know what to go read up on. Hard to believe i've been
doing this for over 10 years : )

Thanks,

Brent
 
B

Brent

Hey it works!

I did it the first way with a static (notinheritable) class with shared
functions. The other thing i had to do was to stub out a private
constructor:

Public NotInheritable Class BizGUI

Private Sub New()
'Seal this class off. Throws a compile error if consumer tries to
instantiate.
End Sub

Public Shared Function backToTop() As String
Return "<a href='#top' class=back>back&nbsp;to&nbsp;top</a><BR
clear=all><BR>"
End Function

Public Shared Function vSpacer(ByVal NumPixelsIN As Int16) As String
Return "<img src='./images/blank.gif' width=1 height=" &
NumPixelsIN.ToString & " border=0>"
End Function

End Class

Thanks!

Brent
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top