User Controls

W

Wayne Wengert

This is my first attempt to use a User Control and I am totally confused.
Basically, I am rewriting a set of ASP pages in ASP.NET (VB). The old ASP
files used Include files for common sub routines like connection, managing
background color on objects with focus, etc.. In looking through my asp.net
books, googling and browsing MS sites I believe that the correct approach is
to use a User Control in place of the Include files? The books all show ascx
files as just containing code - e.g.
<Script runat="Server>
Public PTitile As String = "Sample Title"
</Script>
<html>
<head><title><%PTitle%></title></head>
<body>

Using VSNET2003 I create a new User Control and I get the layout for a form
(e.g. PageLoad etc.).

I want to "include" several subroutines and some common code in numerous
aspx pages. The result I want is that the code that calls the subroutines
included in the user control and the subroutines themselves will be added to
the aspx cage where I "include" that user control.

Any concrete (and simple) examples will be much appreciated.

Wayne
 
K

Karl Seguin

Wayne:
User controls are more meant to represent a reusable visual component. As I
understand it you are more interested in having reusable functionality.
This is typically achieved by creating a class (typically wiht shared
methods):

utility.vb -->
public class Utility
public shared function FormatTextToHtml(byval text as string) as String
'do some stuff
return newString
end function

public share function SomethingElse(...) as something
...
end function
end class


then from your codebehid you can make use of this via:
Utility.FormatTextToHtml("asda")


Karl
 

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

Top