473,387 Members | 1,721 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,387 software developers and data experts.

Sharing Behind-page-code

I have some functions in Default.aspx.cs that are accessed by
Default.aspx. I have a new page with the imaginative name of
Default2.apsx. I want to be able to call my functions i Default.aspx.cs
from this new page (as well as from the original page). I could move my
shared code to .Net bin and then use the <@ Import
Namespace="MyCustomNamespace" > at the top of each page, but I was
wondering what other options are available so that I do things the
Asp.Net way and which is the most advised. I'm using .Net 2.0 and
Asp.Net 2.0.

Any suggestions warmly appreciated!
Jun 6 '06 #1
8 1636
Creating a separate class is the only good idea. You can simply reference it
and make the members static (if that makes sense in this case) or you can
create a base-page and have your pages inherit from it.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Mr Flibble" <mr********@flibbyly.wobbly.n.et> wrote in message
news:e6***********@custnews.inweb.co.uk...
I have some functions in Default.aspx.cs that are accessed by
Default.aspx. I have a new page with the imaginative name of
Default2.apsx. I want to be able to call my functions i Default.aspx.cs
from this new page (as well as from the original page). I could move my
shared code to .Net bin and then use the <@ Import
Namespace="MyCustomNamespace" > at the top of each page, but I was
wondering what other options are available so that I do things the
Asp.Net way and which is the most advised. I'm using .Net 2.0 and
Asp.Net 2.0.

Any suggestions warmly appreciated!

Jun 6 '06 #2
* Karl Seguin [MVP] wrote:
Creating a separate class is the only good idea. You can simply reference it
and make the members static (if that makes sense in this case) or you can
create a base-page and have your pages inherit from it.

Karl


I've created a seperate class and called it Common.cs. I've then put it
in the app_code folder. However since moving the code from the
Default.aspx.cs class to the Common.cs class it seems I'm unable to
access the Response object.

I get:

The name 'Response' does not exist in the current context.

Does that mean that shared code can only be code that doesn't alter the
HttpResponse ?

In which case I'm up s**t creak without a paddle ;-)
Jun 6 '06 #3

Mr Flibble wrote:
* Karl Seguin [MVP] wrote:
Creating a separate class is the only good idea. You can simply reference it
and make the members static (if that makes sense in this case) or you can
create a base-page and have your pages inherit from it.

Karl


I've created a seperate class and called it Common.cs. I've then put it
in the app_code folder. However since moving the code from the
Default.aspx.cs class to the Common.cs class it seems I'm unable to
access the Response object.

I get:

The name 'Response' does not exist in the current context.

Does that mean that shared code can only be code that doesn't alter the
HttpResponse ?

In which case I'm up s**t creak without a paddle ;-)


You need to reference System.Web to get to
HttpContext.Current.Response.Write for non-code behind files.

Jun 6 '06 #4
If you need to access the Response object create a class that your pages
can inherit from. In the class place this shared functionality.

Mr Flibble wrote:
* Karl Seguin [MVP] wrote:
Creating a separate class is the only good idea. You can simply reference it
and make the members static (if that makes sense in this case) or you can
create a base-page and have your pages inherit from it.

Karl


I've created a seperate class and called it Common.cs. I've then put it
in the app_code folder. However since moving the code from the
Default.aspx.cs class to the Common.cs class it seems I'm unable to
access the Response object.

I get:

The name 'Response' does not exist in the current context.

Does that mean that shared code can only be code that doesn't alter the
HttpResponse ?

In which case I'm up s**t creak without a paddle ;-)

Jun 6 '06 #5
* ^MisterJingo^ wrote:
You need to reference System.Web to get to
HttpContext.Current.Response.Write for non-code behind files.


Ah OK, so basically I have to use HttpContext.Current.Response.Write
rather than Response.Write?
Jun 6 '06 #6
"Response" is available to you in your codebehind, because the Page class
(which you inherit from) basically has a property:

protected HttpResponse Response
{
get { return HttpContext.Current.Response; }
}

i.e., it creates a shortcut for you....

since you aren't inheriting from Page, you've lost the shortcut

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Mr Flibble" <mr********@flibbyly.wobbly.n.et> wrote in message
news:e6***********@custnews.inweb.co.uk...
* ^MisterJingo^ wrote:
You need to reference System.Web to get to
HttpContext.Current.Response.Write for non-code behind files.


Ah OK, so basically I have to use HttpContext.Current.Response.Write
rather than Response.Write?

Jun 6 '06 #7
re:
basically I have to use HttpContext.Current.Response.Write
rather than Response.Write?
Correct...

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mr Flibble" <mr********@flibbyly.wobbly.n.et> wrote in message
news:e6***********@custnews.inweb.co.uk...* ^MisterJingo^ wrote:
You need to reference System.Web to get to
HttpContext.Current.Response.Write for non-code behind files.


Ah OK, so basically I have to use HttpContext.Current.Response.Write
rather than Response.Write?

Jun 6 '06 #8
* Karl Seguin [MVP] wrote:
"Response" is available to you in your codebehind, because the Page class
(which you inherit from) basically has a property:

protected HttpResponse Response
{
get { return HttpContext.Current.Response; }
}

i.e., it creates a shortcut for you....

since you aren't inheriting from Page, you've lost the shortcut

Karl


Thank you for your excellent explanation. :-)
Jun 6 '06 #9

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

Similar topics

1
by: Meghna | last post by:
Hi, I was wondering if some one would be able to help me with this. I am trying to share a session across two servers and I seem to be experiencing some problems. I was wondering if anybody has...
3
by: Alex | last post by:
Hi all, I want to write a "File sharing system". Is posssible with socket and thread create multisuer connection at the same time ? or is wrong my idea?? thanks
83
by: theodp | last post by:
While Mainframe and Unix users are unlikely to find it novel that Windows XP allows several family members to share a PC while enabling each to have personalized settings and folders, that's not...
2
by: Vitaly | last post by:
Hi, I've encountered a problem sharing c# application in NetMeeting. The problem is that when I try to share some GUI application, I don't see it on remote computer. Sometimes I see random small...
5
by: Jeff | last post by:
Hi - I'm creating an installation program that will install a VB.NET program and an instance of MSDE on an unknown desktop (commercial application). The install will include the MSDE...
21
by: axlq | last post by:
Someone please tell me if I've discovered a PHP bug. I'm sitting in front of several computers on my home network, behind a NAT firewall/router. I am testing my web site on these different...
8
by: mc | last post by:
I would like to be able to send from an ASP.NET page an email which when recieved takes the form of a "Sharing Invitation for a RSS Feed"...
11
by: limperger | last post by:
Hello everybody! I have just found out that the sharing properties of a single database (mdb file on a network), accessed by 3 users, change depending on the user accessing the database. That is,...
4
by: Jerry Spence1 | last post by:
I'm doing: Dim Contents() As String = System.IO.File.ReadAllLines("C:\MyFile.txt") with upwards of 100,000 lines. This is a brilliantly simple and fast way of creating an array from a text...
1
by: strconv | last post by:
Hi, i get a project about; to showing videos and mp3 on server but without sharing. is it possible to do with winsock ? i have a server(xp pro) and i have 20+ client. but there is no file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.