Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Questions on Inheritance. 1

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
Okay, so I put Codebehind="sourcepage.vb" and I can use Design view in VS.Net. However, my question is, I want use one codebehind page (.vb) that uses/inherits from another .vb page. Ie. I have index.aspx with index.aspx.vb as the codebehind. But I want index.aspx.vb to use commonFunctions.vb as well... what's the best way to do this?
 
Just make sure that the commonfunctions.vb is within a module declaration in your file, make sure they're declared public, and ensure its part of your project.

Then all yoru code should be able to access them
:)

D
 
Okay, maybe it's this code... but I have no idea what that meant... I am going to post the 3 pages to that Workgroup thing as soon as I'm accepted. I really need some help... Just trying to learn as fast as I can.
 
np. I just processed your registration to the workgroup.

Let me know when the files are posted up.

D
 
K, they are up. The page, seniors.aspx, asks for a Job number. When it is entered, the 'Lookup Job' button disappears, and is replaced with a ListBox which contains the files the particular job has available. Then the user can specify print sizes, packages, and other various items for each file. (Also, when a file is selected it appears in the image location.) As the files are added to the order, the inline frame lists the files ordered, and they are removed from the ListBox. (The inline frame file can work standalone, so I don't need to focus on it now.)

Codebehind.vb is my common controls used by several of my pages in this application.

Seniors.aspx.vb is all the code for the functions of the page.
 
heh, ok, I've re-uploaded your code pages. i didn't test out hte functionality yet, but i did clean it up and I think i can answer your questions now:

When you create an aspx page, it automatically has a .vb file created as its code behind, and is automatically hooked up to the page. its best NOT to toy with those settings in the aspx design view, as it can get hairy.

There are a few simple ways to share code accross yoru pages:
1. Create a module file (all that is is a .vb file, but inside it has a declaration like this:

Module SomeName
'put your subs/functions here
End Module


Any subs that you delcare public can be accessed from any other files in your project. BUT, in your case, you were trying to access the Application variables in your shared code. This won't work for that, because the modules can't access the Application or Session level variables. so you can either pass those variables from the page, or...

2. Create a class, put the subs/functions within the class, then create an instance of the class (object) when you want to use the code. You'll have to pass in the variables in the same way as well.

But whatever you do, don't try and do the inheritance thing of a code page to a code behind! In old school asp that worked, but its a recipe for disaster with .NET

Take a look at what I did for the pages, and if you have any other questions fire away
:)

hth

D'Arcy
 
ps: you actually don't need teh codebehind.vb file anymore. I put the subs you had from there into the codebehind for the page (seniors.aspx.vb) in a region called Extra Code.

D
 
Well... what about other pages that use codebehind.vb... I'll have to play around with it. So instance of the class... hmmm... K, let me work with it.
 
New question on this... you said that modules cannot access Application variables (like the ones I have set in Global.asax). Can I move those variables (actually constants) into the module itself? Web Forms that use those variables are going to use the functions in that module anyways. I have yet to try it, but I am thinking, in the module:

Public dbAccess As String = "database information"
 
yup, you could do that.

Actually, i forgot to mention: there's documentation that says you should NEVER put any sort of sensitive information (like db connection strings) in Application variables, they should always be stored somewhere else (i.e. web.config file, or as a constant like you're thinking).

D
 
I changed my seniors.aspx page to read:
Code:
<%@ Page Language=&quot;vb&quot; Debug=&quot;True&quot; Inherits=&quot;localhost.seniors&quot; Src=&quot;seniors.aspx.vb&quot; CodeBehind=&quot;seniors.aspx.vb&quot; AutoEventWireup=&quot;false&quot; %>

And put your code in that .vb file. Now when I try to load my page I get a compilation error on this line:
Code:
Session(&quot;ybJob&quot;) = Trim(ybjobNum.Text)

Saying: Name 'Trim' is not declared.
 
make sure you have a reference to whatever library uses the trim function.

D
 
Sorry, found my own answer, on a couple of questions. You guys have all helped a bunch. I actually got it working with codebehind after going through it with VS. I changed it to the obvious:
Code:
Session(&quot;ybJob&quot;) = ybjobNum.Text.Trim
I will experiment with Modules tomorrow... please don't call in sick... hehe... ;)

BTW, I wasn't sure which post in particular to star, so I just did the first one...

Zarcom, you too buddy.
 
NP
if your ever unsure who to star just hand em out they are free. lol

Check out this thread in the ethics forum about the whole star system.
....
......
.........
Interesting it seems to have been deleted. Will get back to you on that.

Anyway the jist of the thread was that the star system is helpfull not only in letting a member know that their help was appreciated but also to other members so that they can determine how helpful a post from someone may be. etc etc.

Once again glad to help That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top