473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1577
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(object date) {
if (date == DBNull.Value){
return "n/a";
}
try{
return ((DateTime)date).ToShortDateString();
}catch{
return "n/a";
}
}
}
}
can be used from your aspx page, such as:

<asp:Repeater id="repeater" Runat="server">
<ItemTemplate>
<%# misc.Utility.FormatDate(DataBinder.Eval(Container. 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.FormatDate(DataBinder.Eval(Container.DataI tem,
"Ordered"))%>
</ItemTemplate>
</asp:Repeater>
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Guoqi Zheng" <no@sorry.nl> wrote in message
news:%2****************@TK2MSFTNGP12.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.Page
{
// any common functions in here
}

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

public class MyCodeBehindPage : MyBasePage
{
}

-- bruce (sqlwork.com)


"Guoqi Zheng" <no@sorry.nl> wrote in message
news:%2****************@TK2MSFTNGP12.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****************@TK2MSFTNGP10.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(object date) {
if (date == DBNull.Value){
return "n/a";
}
try{
return ((DateTime)date).ToShortDateString();
}catch{
return "n/a";
}
}
}
}
can be used from your aspx page, such as:

<asp:Repeater id="repeater" Runat="server">
<ItemTemplate>
<%# misc.Utility.FormatDate(DataBinder.Eval(Container. 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.FormatDate(DataBinder.Eval(Container.DataI tem,
"Ordered"))%>
</ItemTemplate>
</asp:Repeater>
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Guoqi Zheng" <no@sorry.nl> wrote in message
news:%2****************@TK2MSFTNGP12.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**************@TK2MSFTNGP10.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****************@TK2MSFTNGP10.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(object date) {
if (date == DBNull.Value){
return "n/a";
}
try{
return ((DateTime)date).ToShortDateString();
}catch{
return "n/a";
}
}
}
}
can be used from your aspx page, such as:

<asp:Repeater id="repeater" Runat="server">
<ItemTemplate>
<%# misc.Utility.FormatDate(DataBinder.Eval(Container. 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.FormatDate(DataBinder.Eval(Container.DataI tem,
"Ordered"))%>
</ItemTemplate>
</asp:Repeater>
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Guoqi Zheng" <no@sorry.nl> wrote in message
news:%2****************@TK2MSFTNGP12.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**************@TK2MSFTNGP12.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
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...
1
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...
18
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...
171
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)...
1
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...
3
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...
6
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...
2
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...
13
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.