Print Page | Close Window

Include?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=6703
Printed Date: 28 March 2026 at 2:24am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Include?
Posted By: Boecky
Subject: Include?
Date Posted: 25 October 2003 at 8:31am

Hey!
Since a few weeks I'm studying asp.net and I can't find this answer in any book...I hope you guys can

In classic asp you can include pages with only some code (functions and subs) into an other page. Can I do this too in vs with asp.net? What I really want is to use the same functions and subs in some different code behind pages. Do I have to make a module or a class (with this common subs and functions in) or is it something else?

Boecky




Replies:
Posted By: Diep-Vriezer
Date Posted: 25 October 2003 at 8:43am

You'll have to make a class or module, I had the same problem a while ago.

Something like this will work:

Public Class Test
'This is the class file

Public Function ABC()

   Return True

End Function
End Class

This is how you call the function in a page:

Dim Test As New Test

Return Test.ABC()



-------------
Gone..


Posted By: Boecky
Date Posted: 25 October 2003 at 9:07am
Ah ok, I'll try that, thanks


Posted By: Boecky
Date Posted: 25 October 2003 at 9:14am
And what is the module then? Coz in many .net sites they talk about some modules. Oh it seems that I got the same question as diepvriezer now, what's the difference between classes and modules


Posted By: Diep-Vriezer
Date Posted: 25 October 2003 at 11:35am
Indeed.

-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 25 October 2003 at 11:37am

Oh, one more thing:

Neither a module nor a class can peform any Request or Response actions. That bothers me the most, and I'm looking for a solution on that.



-------------
Gone..


Posted By: The WizeGuy
Date Posted: 25 October 2003 at 4:01pm

For "includes" you donīt build classes or modules You use UserControls.

 

Check this link out: http://www.dotnetjunkies.com/quickstart/aspplus/doc/webpagelets.aspx - http://www.dotnetjunkies.com/quickstart/aspplus/doc/webpagel ets.aspx

You have to skip the Classic ASP thinking. "Nothing" is the same in NET

 

cya,

/PatrikB



Posted By: The WizeGuy
Date Posted: 25 October 2003 at 4:09pm
Originally posted by Diep-Vriezer Diep-Vriezer wrote:

Oh, one more thing:

Neither a module nor a class can peform any Request or Response actions. That bothers me the most, and I'm looking for a solution on that.

OH, yes they can!

Sorry, to much code to write .....

 

Check out the HttpContext namespac:

Response.Write(HttpContext.Current.Request.ServerVariables(" SERVER_NAME")

for example ;o)

Why canīt I just cut and paste code? nothing shows up?

Do I need to use this RTF-box?

cya,
/PatrikB



Posted By: Diep-Vriezer
Date Posted: 25 October 2003 at 4:24pm
Yes I know it now. And, idd, you can use the usercontrols. Sigh, it is all so different..

-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 25 October 2003 at 4:28pm

mmm, response.write from a class? don't think so m8, and the intellisense doesn't show up when I use the HttpContext namespace.

EDIT: It somehow happens to work now



-------------
Gone..


Posted By: The WizeGuy
Date Posted: 25 October 2003 at 4:32pm

sorry, had to delete a "lot of code" that I pasted in from a .aspx-file/vb-file

I have to say: RTFM  (NET Framework SDK) and check out the HttpContext

Set this in a class-method and run it:

Return HttpContext.Current.Request.ServerVariables("SERVER_NAME")

 

bind it to a label or what ever on your aspx-page

cya,
/PatrikB



Posted By: Diep-Vriezer
Date Posted: 25 October 2003 at 4:36pm
I knew that

-------------
Gone..


Posted By: The WizeGuy
Date Posted: 25 October 2003 at 4:38pm

TESTING WITH CODE:

< runat="">Label 

cya,
/PatrikB



Posted By: The WizeGuy
Date Posted: 25 October 2003 at 4:38pm

cut & paste do NOT work for me ...

cya,
/PatrikB



Posted By: Diep-Vriezer
Date Posted: 25 October 2003 at 4:40pm
Not? Weird..

-------------
Gone..


Posted By: The WizeGuy
Date Posted: 25 October 2003 at 4:44pm

the aspx-file start like this:

<@ Page Language="VB" %>
<script runat="server">

etc.

cya,
/PatrikB



Posted By: Diep-Vriezer
Date Posted: 26 October 2003 at 3:32am

Yup, and tons of other stuff (AutoEventWireup etc.)

BTW you were right about the cut n paste stuff. You can't cut n paste from the regular ASPX file, but you can from the Code Behind file editor (VS.NET)... Wicked<%@ Page ="vb" AutoWireup="false" Codebehind="TestAuth.aspx.vb" Inherits="DenHeijer.TestAuth"%><%@ Page ="vb" AutoWireup="false" Codebehind="TestAuth.aspx.vb" Inherits="DenHeijer.TestAuth"%><%@ Page ="vb" AutoWireup="false" Codebehind="TestAuth.aspx.vb" Inherits="DenHeijer.TestAuth"%><%@ Page ="vb" AutoWireup="false" Codebehind="TestAuth.aspx.vb" Inherits="DenHeijer.TestAuth"%><%@ Page ="vb" AutoWireup="false" Codebehind="TestAuth.aspx.vb" Inherits="DenHeijer.TestAuth"%><%@ Page ="vb" AutoWireup="false" Codebehind="TestAuth.aspx.vb" Inherits="DenHeijer.TestAuth"%>



-------------
Gone..


Posted By: Mart
Date Posted: 26 October 2003 at 5:06am

Ive used response.write from a class etc.

If jus put

Protected response As New System.Web.httpResponse

similar for reqeust and server and all the others.

Mart.



Posted By: Boecky
Date Posted: 26 October 2003 at 9:32am

tkx for all the feedback

Both are working, but I used the user controls and that seems me the best solution. If I compare with classic asp, I'll include (for example) a variable with a connection string in every code behind page. (Can be other subs or functions too). Is it the best way to put it in an user control, or is it better to put it in a module or a class? Actually I'm searching for the most optimized way...



Posted By: Diep-Vriezer
Date Posted: 26 October 2003 at 2:07pm
I'm using a public module for all my connections strings and keys. But I don't know if this is the most 'optimized' way. Anyway, everything is fast in asp.net, so it shouldn't matter much.

-------------
Gone..


Posted By: The WizeGuy
Date Posted: 26 October 2003 at 4:57pm

I never use modules.

For connectionString and other keys like default-lang, other configuration options, will be placed in web.config (webapp) or app.config (clientapp)

Then, you can reach them from EVERY method/property IN any class

If I could cut & paste I would give an example ... now, just look up web.config in NET Framework SDK ... or search the http://www.asp.net/ - www.asp.net forum.

cya,
/PatrikB



Posted By: Bunce
Date Posted: 26 October 2003 at 5:54pm

Even better is to create a class which reads the web-config variables into properties of that class. That way you only have to hit the web.config once, rather than every time you lookup the variable.

You will also have intellisense on the variables.

Same thing goes for wrapping up your session variables.. Very handy.

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: Diep-Vriezer
Date Posted: 27 October 2003 at 12:46am

Mmm, I stick with the class I think. It also has intellisense, like every class or module, and works just fine for me, since you can request all the variables FROM something (web.config could be usefull), or just declare them.



-------------
Gone..


Posted By: Boecky
Date Posted: 27 October 2003 at 12:14pm

It would be nice if someone can explain the reply again before in this topic about using respons.write and request in modules and classes. Something there was not that clear for me. Or maybe a good link?



Posted By: MorningZ
Date Posted: 27 October 2003 at 12:25pm

i hate to anser that request for information like this:

but if you are looking to Response.Write from a module or class, you are missing the whole point of Object Oreinted Programming....

it's time to break away from Response.Write....   return a string instead, fill a asp:literal or asp:label with that text



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 27 October 2003 at 12:35pm

I always return strings or booleans. It was about the Request methods. But they are all clear now.



-------------
Gone..


Posted By: Boecky
Date Posted: 28 October 2003 at 2:08pm
all clear for me too now...like above said...starting to think more oop



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net