Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > .ASCX files, ASPX files and code behind

Reply
Thread Tools

.ASCX files, ASPX files and code behind

 
 
=?Utf-8?B?UGF1bA==?=
Guest
Posts: n/a
 
      09-26-2005
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.
 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      09-26-2005
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" <> wrote in message
news020B564-4E8C-489C-90D5-...
>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.



 
Reply With Quote
 
 
 
 
Yup
Guest
Posts: n/a
 
      09-26-2005
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" <> wrote in message
news020B564-4E8C-489C-90D5-...
>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.



 
Reply With Quote
 
Michel de Becdelièvre
Guest
Posts: n/a
 
      09-26-2005

"Paul" <> a écrit dans le message de news:
D020B564-4E8C-489C-90D5-...

> 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).



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Non-code behind to code behind John ASP .Net 2 02-19-2007 07:08 PM
Code behind problems after splitting .ASPX page into multiple files just.an.imbecile ASP .Net 0 06-06-2006 05:33 PM
How to bring aspx code (in HTML view) to the aspx.vb code-behind? Paolo Pignatelli ASP .Net 6 02-21-2005 01:55 AM
Using User Controls, Code-Behind, Components and ASPX files Ric ASP .Net 2 11-30-2004 01:29 PM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57