Saturday, March 31, 2012

Sharing data across web forms?

I am using Infragistics UltraWebTab (a tab folder control for ASP.NET). My
tab folder control will include five tab pages with a separate web form on
each, and these web forms will share data.
My questions regard the data tier, that is, how I should construct the data
objects so as to reduce memory usage while optimizing page performance?
1. I'll be using data sets. How can I share a single data set across the
multiple web forms?
2. Can the data adapters be shared across the pages?
3. If not, what is the memory overhead for having multiple identical data
adapters open?
Thanks in advance,
Mervin Williams1) You can use Session State or create a shard class (class with all shared
methods in VB.NET or static memebers in C#) (use the shared if you want the
data shared by All users, if you want it specific to the individual, session
state will work
2) Yes, but no need to do it. They area perfect object to implement as
Shared or static since their logic is the same across classes
3) DataAdapters are never 'open'. They are declared, possilbly
instantiated, but the only thing that 'opens' is connections. Like anything,
use only as much as you need. However, the dataadapter doesn't give a hoot
about the data per se. It just looks to rowstate to decide what it's going
to do with something. So you can create your own data access layer with
pretty much the same configuration and pass different datasetsto it.
Remember that you can fill a dataset/datatable with one dataadapter and
update say 3 different databases with 3 other data adapters never using the
first one again. I divorces itself from the data as soon as fill/update etc
is complete.
HTH,
Bill
"Mervin Williams" <mwilliams@.innovasolutions.net> wrote in message
news:OhmrDZjHEHA.3444@.TK2MSFTNGP11.phx.gbl...
> I am using Infragistics UltraWebTab (a tab folder control for ASP.NET).
My
> tab folder control will include five tab pages with a separate web form on
> each, and these web forms will share data.
> My questions regard the data tier, that is, how I should construct the
data
> objects so as to reduce memory usage while optimizing page performance?
> 1. I'll be using data sets. How can I share a single data set across the
> multiple web forms?
> 2. Can the data adapters be shared across the pages?
> 3. If not, what is the memory overhead for having multiple identical data
> adapters open?
> Thanks in advance,
> Mervin Williams
>
Hi Mervin,
In addition to Bill, when you really want to save memory you can also use
the viewstate, however you are transporting that to the client of course.
Cor

sharing data between custom controls

I have two custom controls on a page that work on the same object that needs
some prepping when first loaded. Currently I just load them in both controls
individually, essentially doing the same work twice.
What's the best way to share data between controls? I know I could place the
data in HttpContext, but would I essentially be tripling the amount of
memory I'm using? 1 copy in control1, 1 copy in context, and 1 copy in
control2. Unless context works by reference. Otherwise, is there a better
way? The controls inherit from a common class already -- is there any way to
have a variable in that parent class that is shared within a page?
ThanksBTW -- there's no need to persist the data after the page is rendered. Sorry
I didn't clarify this. It's just data used while rendering the controls. The
data is needed by various controls.
"axis" <justposttothenewsgroup@.nospam.com> wrote in message
news:qoy4d.97680$D%.48936@.attbi_s51...
>I have two custom controls on a page that work on the same object that
>needs some prepping when first loaded. Currently I just load them in both
>controls individually, essentially doing the same work twice.
> What's the best way to share data between controls? I know I could place
> the data in HttpContext, but would I essentially be tripling the amount of
> memory I'm using? 1 copy in control1, 1 copy in context, and 1 copy in
> control2. Unless context works by reference. Otherwise, is there a better
> way? The controls inherit from a common class already -- is there any way
> to have a variable in that parent class that is shared within a page?
> Thanks
>
Create the object at the page level and pass it to both controls.
Jonathan Allen
"axis" <justposttothenewsgroup@.nospam.com> wrote in message
news:qoy4d.97680$D%.48936@.attbi_s51...
> I have two custom controls on a page that work on the same object that
needs
> some prepping when first loaded. Currently I just load them in both
controls
> individually, essentially doing the same work twice.
> What's the best way to share data between controls? I know I could place
the
> data in HttpContext, but would I essentially be tripling the amount of
> memory I'm using? 1 copy in control1, 1 copy in context, and 1 copy in
> control2. Unless context works by reference. Otherwise, is there a better
> way? The controls inherit from a common class already -- is there any way
to
> have a variable in that parent class that is shared within a page?
> Thanks
>

sharing data between custom controls

I have two custom controls on a page that work on the same object that needs
some prepping when first loaded. Currently I just load them in both controls
individually, essentially doing the same work twice.

What's the best way to share data between controls? I know I could place the
data in HttpContext, but would I essentially be tripling the amount of
memory I'm using? 1 copy in control1, 1 copy in context, and 1 copy in
control2. Unless context works by reference. Otherwise, is there a better
way? The controls inherit from a common class already -- is there any way to
have a variable in that parent class that is shared within a page?

ThanksBTW -- there's no need to persist the data after the page is rendered. Sorry
I didn't clarify this. It's just data used while rendering the controls. The
data is needed by various controls.

"axis" <justposttothenewsgroup@.nospam.com> wrote in message
news:qoy4d.97680$D%.48936@.attbi_s51...
>I have two custom controls on a page that work on the same object that
>needs some prepping when first loaded. Currently I just load them in both
>controls individually, essentially doing the same work twice.
> What's the best way to share data between controls? I know I could place
> the data in HttpContext, but would I essentially be tripling the amount of
> memory I'm using? 1 copy in control1, 1 copy in context, and 1 copy in
> control2. Unless context works by reference. Otherwise, is there a better
> way? The controls inherit from a common class already -- is there any way
> to have a variable in that parent class that is shared within a page?
> Thanks
Create the object at the page level and pass it to both controls.

--
Jonathan Allen

"axis" <justposttothenewsgroup@.nospam.com> wrote in message
news:qoy4d.97680$D%.48936@.attbi_s51...
> I have two custom controls on a page that work on the same object that
needs
> some prepping when first loaded. Currently I just load them in both
controls
> individually, essentially doing the same work twice.
> What's the best way to share data between controls? I know I could place
the
> data in HttpContext, but would I essentially be tripling the amount of
> memory I'm using? 1 copy in control1, 1 copy in context, and 1 copy in
> control2. Unless context works by reference. Otherwise, is there a better
> way? The controls inherit from a common class already -- is there any way
to
> have a variable in that parent class that is shared within a page?
> Thanks

Sharing Data between ASP and ASP.Net

Presently I program in ASP. With ASP.Net being the new thing, I would like to learn it. As a result, most of my pages are in ASP, but I would like to share data with ASP.Net pages. For example, if a user logs in on an ASP page, I would like to be able to use the same login information on the ASP.Net pages, without requiring the user to log in again. Is there a way to do this other than with FSO and storing a temporary value in the database?One option is to use a cookie that is shared between ASP and ASP.NET. Session state is not shared between ASP and ASP.NET, and hitting a datase each page load is a bit extreme. It iwll likely in the end require changes in the ASP code, and compromises in the ASP.NET code.
this may help :

<a href="http://links.10026.com/?link=http://rtfm.atrax.co.uk/infinitemonkeys/articles/asp.net/993.asp>http://rtfm.atrax.co.uk/infinitemonkeys/articles/asp.net/993.asp</a
ASP and ASP.NET can share :

cookies
querystrings and form posts
data sources

they can't share Session without a third-party addon such as Sessionbridge - www.sessionbridge.com

j

Sharing data between various pages


Hi all,

I am a newbie to asp.net web applications.
My web application consists of various aspx pages. The Default.aspx page is made up offrames, where each of the frames's source is an aspx page. It consists of 3 frames. The first frame's source page is First.aspx. The second frame's source page is Second.aspx. The third's is Third.aspx.

Is itcorrect to have like this. I have made the source of each frame as anaspx page because I want to display the items in each frame usingRepeater control.

The application's start page(which is StartPage.aspx) takes the query string, calculates theresult and sets the value to a variable named Result.
Now I want to use this Result object in the source aspx pages of eachframe. I want to load each of the frames with some values, depending onthe Result value. So, how do I share this variable Result?
Any help will be appreciated

Please help me!!!!!!!!!!!

sairaj:

Hi all, I am a newbie to asp.net web applications.
My web application consists of various aspx pages. The Default.aspx page is made up of frames, where each of the frames's source is an aspx page. It consists of 3 frames. The first frame's source page is First.aspx. The second frame's source page is Second.aspx. The third's is Third.aspx.Is it correct to have like this. I have made the source of each frame as an aspx page because I want to display the items in each frame using Repeater control.
The application's start page(which is StartPage.aspx) takes the query string, calculates the result and sets the value to a variable named Result.
Now I want to use this Result object in the source aspx pages of each frame. I want to load each of the frames with some values, depending on the Result value. So, how do I share this variable Result?
Any help will be appreciated Please help me!!!!!!!!!!!


Regarding the frames, you can use them if you want. However, many developers avoid them because they can be difficult to manage, they are not easily indexed by search engines, they are not supported in some browsers, and so on. Using User Controls and/or Master Pages can almost always replace the use of frames.

Regarding the values, you can read/write data to an object called "Session", which is available on every page, like this...


private void TestWriteToSession()
{
this.Session["MyKey1"] = "some string value";
this.Session["MyKey2"] = 1;
}

private void TestReadFromSession()
{
string myValue1 = Convert.ToString(this.Session["MyKey1"]);
int myValue2 = Convert.ToInt32(this.Session["MyKey2"]);
}

There are many ways to share data. Using Session is just one.

Note that Session is a decent choice under certain conditions, such as -- when it is used to store built-in data types (string, int, double, etc) AND when the data is not too large in terms of storage size-- that is, it is not a good idea to store a string that has 1-million characters in it into Session.

HTH.

Thank you.

-- Mark Kamoski


Hi Mark,

I think I will be more specific to what my application should support. I am trying to write a clustering search web application. So the start page consists of a TextBox and a search button. After the user enters the query into the TextBox, I extract the query, get the results and cluster them into various groups. Now, I want to display the cluster labels on the left side of the page, and the right side should contain all the results. Also, when the user clicks on any cluster label on the left side, the right side should be loaded with the snippets belonging to that particular cluster. Also, the TextBox and the Search button should be there on top of the page, so that users can enter the next query string. Can you give me a suggestion for the approach that I should take.

Thank you


I agree with Mark that you want to avoid frames if possible. for the application that you are talking about I think having a page that consists of several user controls will work very well. One user control would contain the search input, button and search logic. A second user control would contain the consolidated search results The third would display the result details. This could all be perform without the use of controls, but by spliting it into user controls it offers flexibility moving forward.

Here are couple links that you might find useful

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/masterpages/default.aspx

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/userctrl/default.aspx


Here are some links that may help:
How to: Pass Values Between ASP.NET Web Pages

ASP.NET State Management Recommendations

sairaj:

Hi Mark,

I think I will be more specific to what my application should support. I am trying to write a clustering search web application. So the start page consists of a TextBox and a search button. After the user enters the query into the TextBox, I extract the query, get the results and cluster them into various groups. Now, I want to display the cluster labels on the left side of the page, and the right side should contain all the results. Also, when the user clicks on any cluster label on the left side, the right side should be loaded with the snippets belonging to that particular cluster. Also, the TextBox and the Search button should be there on top of the page, so that users can enter the next query string. Can you give me a suggestion for the approach that I should take.

Thank you

I would suggest doing it just as sairaj mentions above-- by using User Controls.

There are other ways too; but, User Controls are pretty easy, very flexible, and will suit the requirements that you have outlined.

HTH.

Thank you.

-- Mark Kamoski

Sharing database connection with controls

Hi. I'm writing controls that have to query the database, and it
bothers me that I might have several of these controls on a page that
each create, open, and close their own connection with the same
connection string, and the page class has a connection object too.

I'm using the code-behind way of doing things, and I considered
leaving the database connection open as a field in the page's class
and somehow letting the controls use that same connection, but then I
want to be sure that every page does have a database connection
object.

What is the best way of sharing the database connection object between
the page's class and the controls' classes? Can I create a connection
object on the page automatically some way in global.asax?

Thanks,
Mike PIIIf you use exactly the same connection string, asp.net (rather ado.net for
this matter) will automatically share the same connection between all your
objects. This is called "connection pooling". The best practice is to put
the code to open connection just before the database access operation and to
close it as soon as you finish the operation. Ado.net will take care about
actual opening and closing connections. Trying to keep connection open will
result in degrading performance.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike P2" <sumguyovrthar@.gmail.comwrote in message
news:1180839750.113116.100420@.g4g2000hsf.googlegro ups.com...

Quote:

Originally Posted by

Hi. I'm writing controls that have to query the database, and it
bothers me that I might have several of these controls on a page that
each create, open, and close their own connection with the same
connection string, and the page class has a connection object too.
>
I'm using the code-behind way of doing things, and I considered
leaving the database connection open as a field in the page's class
and somehow letting the controls use that same connection, but then I
want to be sure that every page does have a database connection
object.
>
What is the best way of sharing the database connection object between
the page's class and the controls' classes? Can I create a connection
object on the page automatically some way in global.asax?
>
Thanks,
Mike PII
>


"Mike P2" <sumguyovrthar@.gmail.comwrote in message
news:1180839750.113116.100420@.g4g2000hsf.googlegro ups.com...

Quote:

Originally Posted by

I considered leaving the database connection


As Eliyahu mentions, this is one of the worst things you can do in terms of
performance and scalability of an ASP.NET app...

--
http://www.markrae.net
On Jun 3, 3:46 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

If you use exactly the same connection string, asp.net (rather ado.net for
this matter) will automatically share the same connection between all your
objects. This is called "connection pooling". The best practice is to put
the code to open connection just before the database access operation and to
close it as soon as you finish the operation. Ado.net will take care about
actual opening and closing connections. Trying to keep connection open will
result in degrading performance.
>
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net


Cool. So is the stuff in the System.Data.SqlClient Ado.net? Or do I
have to use those OLE classes?

Thanks for your replies,
Mike PII
System.Data.SqlClient is fine.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike P2" <sumguyovrthar@.gmail.comwrote in message
news:1180880364.258338.178210@.p47g2000hsd.googlegr oups.com...

Quote:

Originally Posted by

On Jun 3, 3:46 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

>If you use exactly the same connection string, asp.net (rather ado.net
>for
>this matter) will automatically share the same connection between all
>your
>objects. This is called "connection pooling". The best practice is to put
>the code to open connection just before the database access operation and
>to
>close it as soon as you finish the operation. Ado.net will take care
>about
>actual opening and closing connections. Trying to keep connection open
>will
>result in degrading performance.
>>
>--
>Eliyahu Goldin,
>Software Developer & Consultant
>Microsoft MVP
>[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net


>
Cool. So is the stuff in the System.Data.SqlClient Ado.net? Or do I
have to use those OLE classes?
>
Thanks for your replies,
Mike PII
>

Sharing database connection with controls

Hi. I'm writing controls that have to query the database, and it
bothers me that I might have several of these controls on a page that
each create, open, and close their own connection with the same
connection string, and the page class has a connection object too.
I'm using the code-behind way of doing things, and I considered
leaving the database connection open as a field in the page's class
and somehow letting the controls use that same connection, but then I
want to be sure that every page does have a database connection
object.
What is the best way of sharing the database connection object between
the page's class and the controls' classes? Can I create a connection
object on the page automatically some way in global.asax?
Thanks,
Mike PIIIf you use exactly the same connection string, asp.net (rather ado.net for
this matter) will automatically share the same connection between all your
objects. This is called "connection pooling". The best practice is to put
the code to open connection just before the database access operation and to
close it as soon as you finish the operation. Ado.net will take care about
actual opening and closing connections. Trying to keep connection open will
result in degrading performance.
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike P2" <sumguyovrthar@.gmail.com> wrote in message
news:1180839750.113116.100420@.g4g2000hsf.googlegroups.com...
> Hi. I'm writing controls that have to query the database, and it
> bothers me that I might have several of these controls on a page that
> each create, open, and close their own connection with the same
> connection string, and the page class has a connection object too.
> I'm using the code-behind way of doing things, and I considered
> leaving the database connection open as a field in the page's class
> and somehow letting the controls use that same connection, but then I
> want to be sure that every page does have a database connection
> object.
> What is the best way of sharing the database connection object between
> the page's class and the controls' classes? Can I create a connection
> object on the page automatically some way in global.asax?
> Thanks,
> Mike PII
>
"Mike P2" <sumguyovrthar@.gmail.com> wrote in message
news:1180839750.113116.100420@.g4g2000hsf.googlegroups.com...

> I considered leaving the database connection
As Eliyahu mentions, this is one of the worst things you can do in terms of
performance and scalability of an ASP.NET app...
http://www.markrae.net
On Jun 3, 3:46 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.org> wrote:
> If you use exactly the same connection string, asp.net (rather ado.net for
> this matter) will automatically share the same connection between all your
> objects. This is called "connection pooling". The best practice is to put
> the code to open connection just before the database access operation and
to
> close it as soon as you finish the operation. Ado.net will take care about
> actual opening and closing connections. Trying to keep connection open wil
l
> result in degrading performance.
> --
> Eliyahu Goldin,
> Software Developer & Consultant
> Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
Cool. So is the stuff in the System.Data.SqlClient Ado.net? Or do I
have to use those OLE classes?
Thanks for your replies,
Mike PII
System.Data.SqlClient is fine.
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike P2" <sumguyovrthar@.gmail.com> wrote in message
news:1180880364.258338.178210@.p47g2000hsd.googlegroups.com...
> On Jun 3, 3:46 am, "Eliyahu Goldin"
> <REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.org> wrote:
> Cool. So is the stuff in the System.Data.SqlClient Ado.net? Or do I
> have to use those OLE classes?
> Thanks for your replies,
> Mike PII
>