Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 23rd, 2007, 10:05 AM
Authorized User
 
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Subs in module not accessible!?

Hi all,
This is probably a very simple question. A co-worker started a project in VS2005, just doing a few page mockups, and I'm filling things in. In my Items.aspx.vb code, I have to access the database, so I thought I'd do it as I've done in ASP 1 - have a separate Modules folder with a DatabaseFunctions.vb module in it, containing the sub that actually calls the stored proc.
However, In Items.aspx.vb, it doesn't recognize the sub, even when I preface it with "DatabaseFunctions.".
I saw a mention or two of the App_Code folder, but putting DatabaseFunctions.vb there doesn't work either.
Any pointers are very appreciated... hopefully it's simple.
Thanks in advance!

 
Old May 23rd, 2007, 10:09 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What is the protection level of your method? It sounds as though you have it defined as Private.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 25th, 2007, 10:43 AM
Authorized User
 
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It wasn't that, but it was about as basic...
I moved my DatabaseFunctions.vb to the App_Code folder, where in VS2005 all code modules have to be. What I then I had to do, which I didn't realize when I wrote the question, was:
1. Replace the Module / End Module with a class name,
2. Add a namespace.
3. In my pagename.aspx.vb, imports the namespace, instantiate the class, and then I could access classname.functionname().

Thanks for taking the time to answer - I and other semi-ignernt newbies appreciate it.

 
Old May 25th, 2007, 10:56 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Why did you create a new namespace for your class? While this is perfectly acceptable, I am not sure of the logic behind it.

For example, if you name your web project MySite, all of your code behind files and everything else becomes part of the namespace MySite. So, if i wanted to access code in pagename.aspx.vb I would do something like

Imports MySite

...code
MySite.pagename.[function or method]

So you are placing a Namespace within a namespace which is somewhat redundant for what you are doing. What you could do instead is remove the namespace from your class so all you have is your class declaration

Public Class DataBaseFunctions

End Class

You can then create an instance (assuming you have instance members in the class) of the object and access it directly without importing the namespace. So something like this

Dim df as New DatabaseFunctions()
df.[method/function]()

In any case, glad you got it working.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 31st, 2007, 08:06 AM
Authorized User
 
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi dparsons,
Just saw your post (the replies were being sent to my home email account).
You're right - I don't know why I thought a namespace was necessary. Probably it was still a Module when I added the namespace, and I left the namespace in there when I made it a class.
Embarrassing... I'm really not a moron.
Thanks again.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem passing variables between Subs dgr7 Beginning VB 6 2 February 16th, 2007 06:40 PM
accessible forms nclisgo BOOK: Accessible XHTML and CSS Web Sites: Problem Design Solution 0 June 9th, 2005 05:57 AM
Calling external classes and/or subs/funcs jmischo VBScript 2 December 16th, 2004 08:45 AM
Question about Subs stu9820 ASP.NET 1.0 and 1.1 Basics 7 November 26th, 2003 08:53 AM
Calling subs & Functions Zooker Beginning VB 6 4 August 20th, 2003 07:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.