• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Another ASP .NET Question

clamum

Lifer
I have a bunch of functions that I'd like to put in a DLL file that different pages of the web app can access, rather than putting them in the actual .aspx pages.

I'm just not sure what I need to do to accomplish this. I tried creating a new Windows Control Library but I don't think that's gonna work. Should I made a new Class Library instead? That seems like it would be closer to what I need.
 
Just create a new class library and put all the functions in it then make sure its accessible in the /bin directory - or sign it and put it in the GAC if you want it accessible to multiple web apps.
 
Originally posted by: WannaFly
Just create a new class library and put all the functions in it then make sure its accessible in the /bin directory - or sign it and put it in the GAC if you want it accessible to multiple web apps.
I started doing that but was getting "Not declared" errors on some things (Such as Request). I'm not sure what I need to import or do to get that web functionality in the Class Library.
 
It doesn't need to be a different dll if it's all within the same app. Just add a class and use the class within the pages. If it is a different dll then you add a new class library project to your existing solution, then in the web app add a reference, project, select the new project.
 
Originally posted by: torpid
It doesn't need to be a different dll if it's all within the same app. Just add a class and use the class within the pages. If it is a different dll then you add a new class library project to your existing solution, then in the web app add a reference, project, select the new project.

.NET is new to me so this may sound dumb, but where would the class go? In any of the .aspx pages?
 
You've got 2 options.

You just create a new class - it can go in any .cs (or .vb) file, but it's better practice to put it in its own seperate file - that way it's easier to find it to modifiy/copy it.

If you're using visual studio - you just right click on your project - add new class. It'll create a new file for you, and put the appropriate starting points in for you.

You can then access that class from any file that references your class. It can either be referenced by having the .cs file in the same project - or compiling the project into its own dll and then adding a reference to that dll in your project. Note - you will need to make sure that you add the appropriate namespaces to your code, so that your class can be found.

To deploy your project - you just need to bundle the dll containing your class with the dll containing the rest of your project so that all the dlls go in the same directory. The alternative is to register the dll containing your class with the global assembly cache - this means any code on your computer can find it and use it - but it's a bit more difficult to set up.
 
Originally posted by: Mark R
You've got 2 options.

You just create a new class - it can go in any .cs (or .vb) file, but it's better practice to put it in its own seperate file - that way it's easier to find it to modifiy/copy it.

If you're using visual studio - you just right click on your project - add new class. It'll create a new file for you, and put the appropriate starting points in for you.

You can then access that class from any file that references your class. It can either be referenced by having the .cs file in the same project - or compiling the project into its own dll and then adding a reference to that dll in your project. Note - you will need to make sure that you add the appropriate namespaces to your code, so that your class can be found.

To deploy your project - you just need to bundle the dll containing your class with the dll containing the rest of your project so that all the dlls go in the same directory. The alternative is to register the dll containing your class with the global assembly cache - this means any code on your computer can find it and use it - but it's a bit more difficult to set up.

Duh, should've thought of that. Thanks for the help guys!
 
Are you using .NET 1.1 or 2.0?

If you're using 2.0, look to see if you have a folder called App_Code. If you don't, right-click on your web site name, Add Folder and add App_Code. Now that you have your App_Code folder, this is where miscellaneous classes like this belong. I recommend you create other folders in this one to keep them organized.

If you're using 1.1, then there is no designated place to put the code so just create them whereever it makes sense (I'd still recommend keeping it logically organized).

-Jax
 
I'm using .NET 1.1.

I created a new class file in the project like you said Mark, and added some Imports at the top but I'm still getting the "Not declared" errors on web objects like Request and Session... any ideas?
 
Originally posted by: clamum
I'm using .NET 1.1.

I created a new class file in the project like you said Mark, and added some Imports at the top but I'm still getting the "Not declared" errors on web objects like Request and Session... any ideas?

In reality- you shouldnt be using request and session in the class file. You should pass them in as strings/whatever to the function call from the original page.

But if you must, use imports and make sure you have references added to those namespaces.

 
Originally posted by: WannaFly
Originally posted by: clamum
I'm using .NET 1.1.

I created a new class file in the project like you said Mark, and added some Imports at the top but I'm still getting the "Not declared" errors on web objects like Request and Session... any ideas?

In reality- you shouldnt be using request and session in the class file. You should pass them in as strings/whatever to the function call from the original page.

But if you must, use imports and make sure you have references added to those namespaces.

Good advice. Worth repeating.

Personally, I'd take the first option - define your methods to take the query string or session data as parameters. Use the Web context objects only in the context of the calling page - it makes things a lot easier if you subsequently want to reuse your code somewhere else.

 
Originally posted by: Mark R
Originally posted by: WannaFly
Originally posted by: clamum
I'm using .NET 1.1.

I created a new class file in the project like you said Mark, and added some Imports at the top but I'm still getting the "Not declared" errors on web objects like Request and Session... any ideas?

In reality- you shouldnt be using request and session in the class file. You should pass them in as strings/whatever to the function call from the original page.

But if you must, use imports and make sure you have references added to those namespaces.

Good advice. Worth repeating.

Personally, I'd take the first option - define your methods to take the query string or session data as parameters. Use the Web context objects only in the context of the calling page - it makes things a lot easier if you subsequently want to reuse your code somewhere else.
Yeah that is a much better practice. Thanks for the help I think I'll be able to get this done now haha. 🙂
 
Back
Top