469,890 Members | 1,607 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

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

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
Nov 18 '05 #1
3 1159
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(someParamete r);

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.
-----Original Message-----
What is the most efficient way to code asp.net pages when you break yourpage up into user controls?

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

This seems bloatful (my new word).

Just wondering,

Brent
.

Nov 18 '05 #2
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
"Kikoz" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
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(someParamete r);

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.
-----Original Message-----
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
.

Nov 18 '05 #3
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
"Kikoz" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
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(someParamete r);

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.
-----Original Message-----
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
.

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

47 posts views Thread by Neal | last post: by
6 posts views Thread by Peter Frost | last post: by
1 post views Thread by Abareblue | last post: by
3 posts views Thread by Mr Newbie | last post: by
3 posts views Thread by clintonG | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.