[thelist] vb.net: using subroutines within user controls - .ascx

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Mon Oct 11 17:36:03 CDT 2004


	First off, you should never see those <% tags anywhere in your
ASP.NET code.  It's not worth the hassle.

	Second, your tag declaration in the page is probably wrong if
you're using the subroutine name as the second part of the tag.  Public
methods aren't called by a tag name.  Is there any worthwhile sample
code in this book?  You might take a look at the ASP.NET Quickstarts for
some real help (they have a nice little section on user controls):

	Third, you shouldn't be using Response.Write at all; use a
Literal control instead for best practices and better performance (plus,
you know exactly where the text will end up).

That's all I can tell you without seeing the rest of the code...


-----Original Message-----
From: thelist-bounces at lists.evolt.org On Behalf Of Casey Crookston

> -----Original Message-----

> Is it possible to use subroutines from within a user control?  If so, 
> what is the syntax for declaring the sub?

------- David Said-----------

> In the code-behind file (the XXX.ascx.vb file) you can declare any sub

> you wish using the following syntax:
> Public Sub SubName()
> 'sub logic
> End Sub

Thanks David.  Okay, so:

<% Public sub header()

response.write("a bunch of html")

end sub %>

Like that?

When I do that, I an error on this line:  <% Public sub header()

Compiler Error Message: BC30289: Statement cannot appear within a method
body. End of method assumed.

Or is it like this:

<script runat="server">

Public sub header()

response.write("a bunch of html")

end sub


When I try that, then the page which calls the user control bombs out.

Line 26: <aspfd:header runat="server"/>

BC30188: Declaration expected.


More information about the thelist mailing list