473,473 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

.ASCX files, ASPX files and code behind

I have a .aspx site.

I have a header that I want on the entire site. So I made it a User Control
..ascx file. In this header, I make one SQL call, so I need to create all the
connection objects, etc.

So I embed that User Control in the .ascx file. No problem.

The problem is I have to make another SQL call in the .aspx file. But it
appears that I can not use the same connection object that I declared in the
..ascx file.

I do not want to create multiple connection object for each page.

Is there a proper way to do this considering the requirements? Maybe use a
code-behind. I only want to create one connection object per page.
Nov 19 '05 #1
3 2009
Why not? As long as you close each connection after you are done with it, it
will be fine (unless we are talking many many connections).

You can also do some things like have a base page with a connection property
exposed, and then have all your user controls get the current page's
connection via this property.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
I have a .aspx site.

I have a header that I want on the entire site. So I made it a User
Control
.ascx file. In this header, I make one SQL call, so I need to create all
the
connection objects, etc.

So I embed that User Control in the .ascx file. No problem.

The problem is I have to make another SQL call in the .aspx file. But it
appears that I can not use the same connection object that I declared in
the
.ascx file.

I do not want to create multiple connection object for each page.

Is there a proper way to do this considering the requirements? Maybe use a
code-behind. I only want to create one connection object per page.

Nov 19 '05 #2
Yup
Behind the scenes, ADO.NET manages a connection pool for you (by default).
It will re-use connections out of this pool or create new ones for you in a
fashion somewhat independent of you creating connection objects in your
code.

-HTH
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
I have a .aspx site.

I have a header that I want on the entire site. So I made it a User
Control
.ascx file. In this header, I make one SQL call, so I need to create all
the
connection objects, etc.

So I embed that User Control in the .ascx file. No problem.

The problem is I have to make another SQL call in the .aspx file. But it
appears that I can not use the same connection object that I declared in
the
.ascx file.

I do not want to create multiple connection object for each page.

Is there a proper way to do this considering the requirements? Maybe use a
code-behind. I only want to create one connection object per page.

Nov 19 '05 #3

"Paul" <Pa**@discussions.microsoft.com> a écrit dans le message de news:
D0**********************************@microsoft.com...
The problem is I have to make another SQL call in the .aspx file. But it
appears that I can not use the same connection object that I declared in
the
.ascx file.

I do not want to create multiple connection object for each page.

Is there a proper way to do this considering the requirements? Maybe use a
code-behind. I only want to create one connection object per page.


The Page object that you get in your ascx is of the aspx's class. You
can expose public methods on it (or declare the base page to derive from an
interface if you need to be generic) and call them. Note however that the
intialisation order is somewhat random, you need to code with this in mind .

However, I would not do that unless I have a significant amount of data
to share (a dataset for instance).

Nov 19 '05 #4

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

Similar topics

4
by: Rob Meade | last post by:
Hi all, I have just put together our organisations 'template' for our web applications and have created 7 .ascx files which when dropped into my template file work perfectly...however, I have a...
2
by: Holger (David) Wagner | last post by:
Hi all, I'd like to have several "skins" for an application that are "structurally different" (i.e. controls at different locations, some controls visible only in a particular "skin"). The...
7
by: Holger (David) Wagner | last post by:
Hi Group, I've searched the Web for precompilers that compile ASPX/ASCX pages just like it can be done with JSPs, but so far, I've only found approaches targetted at increasing the performance....
4
by: Milsnips | last post by:
hi there, Can someone help me out with some example code (VB.NET) here that i need: i would like to programatically check my ASP.NET web application and return a list of all the ASPX and ASCX...
5
by: djscratchnsniffing | last post by:
i know you can access an ascx's properties/methods from an aspx file. Let's say you have an aspx file with two code-behind files(ascx files). Can you access one of the ascx file's...
4
by: ChrisB | last post by:
Hi - I'm just trying to figure out what would be involved with deploying a simple HTML update to an ASCX file. Where there were no changes to the code behind (compiled code), to deploy this to...
6
by: Martin Eyles | last post by:
Hi, I have a .aspx page which has a .ascx file included through the lines <%@ Register TagPrefix="aspcustom" TagName="menu" Src="Menu.ascx" %> and <aspcustom:menu id="Menu1"...
3
by: Steven Nagy | last post by:
Hi all, ASP.NET : Framework 2.0 - C# A recent addition to my code generater will create GridView's and ObjectDataSource's in a control (ASCX). So the code gen creates an ascx, ascx.cs,...
11
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a machine Windows Server 2003 using IIS 6.0 and I am getting the error BC30560 prjob_ascx is ambiguous in the namespace ASP I found a fix. Deleting all the files in the...
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
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.