Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 23rd, 2007, 10:05 AM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
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!

Reply With Quote
  #2 (permalink)  
Old May 23rd, 2007, 10:09 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
  #3 (permalink)  
Old May 25th, 2007, 10:43 AM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
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.

Reply With Quote
  #4 (permalink)  
Old May 25th, 2007, 10:56 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
  #5 (permalink)  
Old May 31st, 2007, 08:06 AM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:31 PM.


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