473,594 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

move code behind file to module

Dear sir,

If I need to use a function on xxx.aspx page, e.g. on a repeater control, I
have to define this function inside xxx.aspx.vb file, if I put it in the
module class, it will not work so I have to copy the same function into all
aspx page which may need it.

Is it possible that I define this function something in the application, I
can use it on every .aspx page??

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

Nov 18 '05 #1
5 1587
Guoqi:
Yes, the function doesn't have to reside in the codebehind file in order to
be usedin your aspx page.

namespace misc{
public sealed class Utility{
private Utility(){}
public static string FormatDate(obje ct date) {
if (date == DBNull.Value){
return "n/a";
}
try{
return ((DateTime)date ).ToShortDateSt ring();
}catch{
return "n/a";
}
}
}
}
can be used from your aspx page, such as:

<asp:Repeater id="repeater" Runat="server">
<ItemTemplate >
<%# misc.Utility.Fo rmatDate(DataBi nder.Eval(Conta iner.DataItem,
"Ordered")) %>
</ItemTemplate>
</asp:Repeater
or you can even put:

<%@ Import namespace="misc " %> at the top of the page and then do:

<asp:Repeater id="repeater" Runat="server">
<ItemTemplate >
<%# Utility.FormatD ate(DataBinder. Eval(Container. DataItem,
"Ordered")) %>
</ItemTemplate>
</asp:Repeater>
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Guoqi Zheng" <no@sorry.nl> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Dear sir,

If I need to use a function on xxx.aspx page, e.g. on a repeater control, I have to define this function inside xxx.aspx.vb file, if I put it in the
module class, it will not work so I have to copy the same function into all aspx page which may need it.

Is it possible that I define this function something in the application, I
can use it on every .aspx page??

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

Nov 18 '05 #2
the best approach for this is to create a base codebehind page, and have all
you other codebehinds inherit from this page.
the base page (myBasePage.cs) :

public class MyBasePage : System.Web.UI.P age
{
// any common functions in here
}

on your code behind page , change the inheritance to MyBasePage:

public class MyCodeBehindPag e : MyBasePage
{
}

-- bruce (sqlwork.com)


"Guoqi Zheng" <no@sorry.nl> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Dear sir,

If I need to use a function on xxx.aspx page, e.g. on a repeater control, I have to define this function inside xxx.aspx.vb file, if I put it in the
module class, it will not work so I have to copy the same function into all aspx page which may need it.

Is it possible that I define this function something in the application, I
can use it on every .aspx page??

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

Nov 18 '05 #3
Are you sure? I always meet an error when I do that.

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Guoqi:
Yes, the function doesn't have to reside in the codebehind file in order to be usedin your aspx page.

namespace misc{
public sealed class Utility{
private Utility(){}
public static string FormatDate(obje ct date) {
if (date == DBNull.Value){
return "n/a";
}
try{
return ((DateTime)date ).ToShortDateSt ring();
}catch{
return "n/a";
}
}
}
}
can be used from your aspx page, such as:

<asp:Repeater id="repeater" Runat="server">
<ItemTemplate >
<%# misc.Utility.Fo rmatDate(DataBi nder.Eval(Conta iner.DataItem,
"Ordered")) %>
</ItemTemplate>
</asp:Repeater
or you can even put:

<%@ Import namespace="misc " %> at the top of the page and then do:

<asp:Repeater id="repeater" Runat="server">
<ItemTemplate >
<%# Utility.FormatD ate(DataBinder. Eval(Container. DataItem,
"Ordered")) %>
</ItemTemplate>
</asp:Repeater>
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Guoqi Zheng" <no@sorry.nl> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Dear sir,

If I need to use a function on xxx.aspx page, e.g. on a repeater control,
I
have to define this function inside xxx.aspx.vb file, if I put it in the
module class, it will not work so I have to copy the same function into

all
aspx page which may need it.

Is it possible that I define this function something in the application,

I can use it on every .aspx page??

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com


Nov 18 '05 #4
It would be helpful if you told us what the error is and perhaps provided
sample code.

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Guoqi Zheng" <no@sorry.nl> wrote in message
news:O4******** ******@TK2MSFTN GP10.phx.gbl...
Are you sure? I always meet an error when I do that.

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Guoqi:
Yes, the function doesn't have to reside in the codebehind file in order to
be usedin your aspx page.

namespace misc{
public sealed class Utility{
private Utility(){}
public static string FormatDate(obje ct date) {
if (date == DBNull.Value){
return "n/a";
}
try{
return ((DateTime)date ).ToShortDateSt ring();
}catch{
return "n/a";
}
}
}
}
can be used from your aspx page, such as:

<asp:Repeater id="repeater" Runat="server">
<ItemTemplate >
<%# misc.Utility.Fo rmatDate(DataBi nder.Eval(Conta iner.DataItem,
"Ordered")) %>
</ItemTemplate>
</asp:Repeater
or you can even put:

<%@ Import namespace="misc " %> at the top of the page and then do:

<asp:Repeater id="repeater" Runat="server">
<ItemTemplate >
<%# Utility.FormatD ate(DataBinder. Eval(Container. DataItem,
"Ordered")) %>
</ItemTemplate>
</asp:Repeater>
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Guoqi Zheng" <no@sorry.nl> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Dear sir,

If I need to use a function on xxx.aspx page, e.g. on a repeater control,
I
have to define this function inside xxx.aspx.vb file, if I put it in the module class, it will not work so I have to copy the same function
into all
aspx page which may need it.

Is it possible that I define this function something in the

application, I can use it on every .aspx page??

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com



Nov 18 '05 #5
I believe your confusion stems from not thinking in Object-oriented terms.
At run-time, there are no "files" involved in the application process. Files
are compiled into classes, and classes are what you need to think about, not
files. For example, you can define multiple classes in a single file. So,
obviously, the file is irrelevant.

If you need functionality to be available to multiple Page classes, you
define that functionality in a class that is separate from your Page class
code. Then you use that class in your Pages.

This is not something you don't already know how to do. Every time you use a
..Net CLR class, function, or namespace, you are referring to classes that
exist outside your Page class. They exist in DLLs that are stored in the
Global Assembly Cache. When you create a file that defines a class,
regardless of whether you compile it into a DLL or not, you are creating the
same thing.

OOP is all about abstraction. Think of the abstract entities, the classes,
rather than the files and code that define them, and you'll be a lot better
off.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Guoqi Zheng" <no@sorry.nl> wrote in message
news:#g******** ******@TK2MSFTN GP12.phx.gbl...
Dear sir,

If I need to use a function on xxx.aspx page, e.g. on a repeater control, I have to define this function inside xxx.aspx.vb file, if I put it in the
module class, it will not work so I have to copy the same function into all aspx page which may need it.

Is it possible that I define this function something in the application, I
can use it on every .aspx page??

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3579
by: Daniel Bickett | last post by:
Hello, I'm writing an application in my pastime that moves files around to achieve various ends -- the specifics aren't particularly important. The shutil module was chosen as the means simply because that is what google and chm searches returned most often. My problem has to do with shutil.move actually putting the files where I ask it to. Citing code wouldn't serve any purpose, because I am using the function in the most straight...
1
2716
by: Asim Jalis | last post by:
Building a Single Assembly DLL with C# and C++ Code I am trying to create a single assembly composed of managed C++ and C# code, and I want to do this on the command line. I have confirmed that I can do this in Visual Studio 2005 using the steps described here: http://blogs.msdn.com/frankpr/archive/2004/07/27/198918.aspx Question: How can I do this on the command line? What is Visual
18
18340
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
171
7675
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
1
1498
by: Steve | last post by:
HI I've run into a big problem I placed my webpage scripting in the code behind here i put out form tags with table linement stufffffffffffffff Response.Write("<form method=post action=catalog300.aspx
3
4169
by: Karel | last post by:
Hello, I have a VB.NET application where I want to move directories over a network. I tried this with system.io.directory.move, but that doesn't work over different volumes. Has anyone a sollution for this problem? thx
6
2034
by: Andy Sutorius via DotNetMonster.com | last post by:
Using the code below the browser just sits and spins. The dll is located in the root of the web app. System.Runtime.Interop is in the using statements. I have tried this in ASP.NET 1.1 and 2.0 and I get the same result. For testing purposes I have hooked it up to a windows app and it performs as expected. Do you know why the dll won't load in asp.net? namespace WebApplication2 { public class _default : System.Web.UI.Page {
2
1795
by: Anthony Bollinger | last post by:
I am still getting up to speed with ASP.NET 2.0 and its companions (VS, VB, etc.). I am successfully using a PagedDataSource in my code-behind module, but I need to reference the PageCount on the page itself to generate links for the pages. I have tried a few things, but I am still limited to old-style (one file) thinking. How can I do this without bringing all my code into the page? Many thanks, Tony
13
3535
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains some javascript code that calls window.open. I pass the resource url of page B to Page A's window.open call. Page B is then loaded and executed but none of the server-side code is rendered. If I view the source of the page, the code (and page...
0
8253
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8009
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8240
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3867
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.