473,837 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variables defined in the partial class - ASP.NET 2.0

I apologise in advance for such a basic question, but I'm hoping someone will
take the time to answer my question.

In my code I define a Dataset :

Partial Class Default_aspx
Dim dsExcel As New DataSet

I fill the Dataset as follows :
Sub btnExcelList_Cl ick(ByVal sender As Object, ByVal e As System.EventArg s)
<snip>
myData.Fill(dsE xcel)
And I try to interrogate it in another sub :-

Sub btnImportLabinf o_Click(ByVal sender As Object, ByVal e As
System.EventArg s)
<snip>
lblOutput.Text = CType(dsExcel.T ables(0).Rows.C ount, String)
However, the scope of dsExcel is lost and I cannot retrieve the data. It
works in ASP.NET 1.1 where the whole class is defined in the code behind page.

I would really appreciate it if someone answered me.
Many thanks in advance,
SteveB.
Nov 19 '05 #1
7 1380
This should work. Can you give us some details on the error message you're
seeing?

-Brock
DevelopMentor
http://staff.develop.com/ballen
I apologise in advance for such a basic question, but I'm hoping
someone will take the time to answer my question.

In my code I define a Dataset :

Partial Class Default_aspx
Dim dsExcel As New DataSet
I fill the Dataset as follows :

Sub btnExcelList_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s)
<snip>
myData.Fill(dsE xcel)
And I try to interrogate it in another sub :-

Sub btnImportLabinf o_Click(ByVal sender As Object, ByVal e As
System.EventArg s)
<snip>
lblOutput.Text = CType(dsExcel.T ables(0).Rows.C ount, String)
However, the scope of dsExcel is lost and I cannot retrieve the data.
It works in ASP.NET 1.1 where the whole class is defined in the code
behind page.

I would really appreciate it if someone answered me.
Many thanks in advance,
SteveB.


Nov 19 '05 #2
Thanks a million for getting back to me. I've simplfied my problem below :-

Partial Class TestVarScope_as px
Dim varStr As String = "Not Set"

Sub btnSet_Click(By Val sender As Object, ByVal e As System.EventArg s)
varStr = "String now set"
End Sub

Sub btnGet_Click(By Val sender As Object, ByVal e As System.EventArg s)
lblOutput.Text = varStr
End Sub
End Class

When I click buttons 'btnSet' followed by 'btnGet', the output label reads
'Not Set'.

Any idea how I get around this problem ? It wasnt a problem in ASPNet 1.1.

"Brock Allen" wrote:
This should work. Can you give us some details on the error message you're
seeing?

-Brock
DevelopMentor
http://staff.develop.com/ballen
I apologise in advance for such a basic question, but I'm hoping
someone will take the time to answer my question.

In my code I define a Dataset :

Partial Class Default_aspx
Dim dsExcel As New DataSet
I fill the Dataset as follows :

Sub btnExcelList_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s)
<snip>
myData.Fill(dsE xcel)
And I try to interrogate it in another sub :-

Sub btnImportLabinf o_Click(ByVal sender As Object, ByVal e As
System.EventArg s)
<snip>
lblOutput.Text = CType(dsExcel.T ables(0).Rows.C ount, String)
However, the scope of dsExcel is lost and I cannot retrieve the data.
It works in ASP.NET 1.1 where the whole class is defined in the code
behind page.

I would really appreciate it if someone answered me.
Many thanks in advance,
SteveB.


Nov 19 '05 #3
I;ve solved it by using a session variable between the subs. Is that the best
way of handling variable postbacks. I assume that viewstate on controls is
maintained between postbacks but I have to manually maintain variable scope
via session state or hidden variables. Is there a "best way".
Many thanks.

"fisab" wrote:
Thanks a million for getting back to me. I've simplfied my problem below :-

Partial Class TestVarScope_as px
Dim varStr As String = "Not Set"

Sub btnSet_Click(By Val sender As Object, ByVal e As System.EventArg s)
varStr = "String now set"
End Sub

Sub btnGet_Click(By Val sender As Object, ByVal e As System.EventArg s)
lblOutput.Text = varStr
End Sub
End Class

When I click buttons 'btnSet' followed by 'btnGet', the output label reads
'Not Set'.

Any idea how I get around this problem ? It wasnt a problem in ASPNet 1.1.

"Brock Allen" wrote:
This should work. Can you give us some details on the error message you're
seeing?

-Brock
DevelopMentor
http://staff.develop.com/ballen
I apologise in advance for such a basic question, but I'm hoping
someone will take the time to answer my question.

In my code I define a Dataset :

Partial Class Default_aspx
Dim dsExcel As New DataSet
I fill the Dataset as follows :

Sub btnExcelList_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s)
<snip>
myData.Fill(dsE xcel)
And I try to interrogate it in another sub :-

Sub btnImportLabinf o_Click(ByVal sender As Object, ByVal e As
System.EventArg s)
<snip>
lblOutput.Text = CType(dsExcel.T ables(0).Rows.C ount, String)
However, the scope of dsExcel is lost and I cannot retrieve the data.
It works in ASP.NET 1.1 where the whole class is defined in the code
behind page.

I would really appreciate it if someone answered me.
Many thanks in advance,
SteveB.


Nov 19 '05 #4
IMHO you were not doing the exact same thing in 1.1.

It's likely you were working in ASP.NET 1.1. on a control property. Here
this is just a member of your class and as such it is not handled by
viewstate.

And as the ASP.NET page lives just the time of the HTTP request, the
variable is then reset. Expected and usual behavior...
You could keep the sesssion variable or register this value explictely in
the page viewstate and so on...

Patrice
--

"fisab" <fi***@discussi ons.microsoft.c om> a écrit dans le message de
news:17******** *************** ***********@mic rosoft.com...
I;ve solved it by using a session variable between the subs. Is that the best way of handling variable postbacks. I assume that viewstate on controls is
maintained between postbacks but I have to manually maintain variable scope via session state or hidden variables. Is there a "best way".
Many thanks.

"fisab" wrote:
Thanks a million for getting back to me. I've simplfied my problem below :-
Partial Class TestVarScope_as px
Dim varStr As String = "Not Set"

Sub btnSet_Click(By Val sender As Object, ByVal e As System.EventArg s) varStr = "String now set"
End Sub

Sub btnGet_Click(By Val sender As Object, ByVal e As System.EventArg s) lblOutput.Text = varStr
End Sub
End Class

When I click buttons 'btnSet' followed by 'btnGet', the output label reads 'Not Set'.

Any idea how I get around this problem ? It wasnt a problem in ASPNet 1.1.
"Brock Allen" wrote:
This should work. Can you give us some details on the error message you're seeing?

-Brock
DevelopMentor
http://staff.develop.com/ballen

> I apologise in advance for such a basic question, but I'm hoping
> someone will take the time to answer my question.
>
> In my code I define a Dataset :
>
> Partial Class Default_aspx
> Dim dsExcel As New DataSet
> I fill the Dataset as follows :
>
> Sub btnExcelList_Cl ick(ByVal sender As Object, ByVal e As
> System.EventArg s)
> <snip>
> myData.Fill(dsE xcel)
> And I try to interrogate it in another sub :-
>
> Sub btnImportLabinf o_Click(ByVal sender As Object, ByVal e As
> System.EventArg s)
> <snip>
> lblOutput.Text = CType(dsExcel.T ables(0).Rows.C ount, String)
> However, the scope of dsExcel is lost and I cannot retrieve the data. > It works in ASP.NET 1.1 where the whole class is defined in the code
> behind page.
>
> I would really appreciate it if someone answered me.
> Many thanks in advance,
> SteveB.

Nov 19 '05 #5
Appreciate the time you took to reply.
In your opinion is it more efficient to store a large dataset in viewstate
or as a session variables when posting back to the same page ?

"Patrice" wrote:
IMHO you were not doing the exact same thing in 1.1.

It's likely you were working in ASP.NET 1.1. on a control property. Here
this is just a member of your class and as such it is not handled by
viewstate.

And as the ASP.NET page lives just the time of the HTTP request, the
variable is then reset. Expected and usual behavior...
You could keep the sesssion variable or register this value explictely in
the page viewstate and so on...

Patrice
--

"fisab" <fi***@discussi ons.microsoft.c om> a écrit dans le message de
news:17******** *************** ***********@mic rosoft.com...
I;ve solved it by using a session variable between the subs. Is that the

best
way of handling variable postbacks. I assume that viewstate on controls is
maintained between postbacks but I have to manually maintain variable

scope
via session state or hidden variables. Is there a "best way".
Many thanks.

"fisab" wrote:
Thanks a million for getting back to me. I've simplfied my problem below :-
Partial Class TestVarScope_as px
Dim varStr As String = "Not Set"

Sub btnSet_Click(By Val sender As Object, ByVal e As System.EventArg s) varStr = "String now set"
End Sub

Sub btnGet_Click(By Val sender As Object, ByVal e As System.EventArg s) lblOutput.Text = varStr
End Sub
End Class

When I click buttons 'btnSet' followed by 'btnGet', the output label reads 'Not Set'.

Any idea how I get around this problem ? It wasnt a problem in ASPNet 1.1.
"Brock Allen" wrote:

> This should work. Can you give us some details on the error message you're > seeing?
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
> > I apologise in advance for such a basic question, but I'm hoping
> > someone will take the time to answer my question.
> >
> > In my code I define a Dataset :
> >
> > Partial Class Default_aspx
> > Dim dsExcel As New DataSet
> > I fill the Dataset as follows :
> >
> > Sub btnExcelList_Cl ick(ByVal sender As Object, ByVal e As
> > System.EventArg s)
> > <snip>
> > myData.Fill(dsE xcel)
> > And I try to interrogate it in another sub :-
> >
> > Sub btnImportLabinf o_Click(ByVal sender As Object, ByVal e As
> > System.EventArg s)
> > <snip>
> > lblOutput.Text = CType(dsExcel.T ables(0).Rows.C ount, String)
> > However, the scope of dsExcel is lost and I cannot retrieve the data. > > It works in ASP.NET 1.1 where the whole class is defined in the code
> > behind page.
> >
> > I would really appreciate it if someone answered me.
> > Many thanks in advance,
> > SteveB.
>
>
>
>


Nov 19 '05 #6
As always a tradeoff :
- with session you'll use up more memory on the server (you could also use
files for example trading some speed for memory)
- with viewstate you'll have a bigger page and hence a bigger transfert time

For big chunks, my personal preference would rather to keep this server side
(you'll have a minimal choice).

In all cases you could expose this as a property so that your application
don't have to know the "storage" you used. This way it will be easir if you
want at some point to change the location where you kept your data...

Patrice
--

"fisab" <fi***@discussi ons.microsoft.c om> a écrit dans le message de
news:62******** *************** ***********@mic rosoft.com...
Appreciate the time you took to reply.
In your opinion is it more efficient to store a large dataset in viewstate
or as a session variables when posting back to the same page ?

"Patrice" wrote:
IMHO you were not doing the exact same thing in 1.1.

It's likely you were working in ASP.NET 1.1. on a control property. Here
this is just a member of your class and as such it is not handled by
viewstate.

And as the ASP.NET page lives just the time of the HTTP request, the
variable is then reset. Expected and usual behavior...
You could keep the sesssion variable or register this value explictely in the page viewstate and so on...

Patrice
--

"fisab" <fi***@discussi ons.microsoft.c om> a écrit dans le message de
news:17******** *************** ***********@mic rosoft.com...
I;ve solved it by using a session variable between the subs. Is that the
best
way of handling variable postbacks. I assume that viewstate on
controls is maintained between postbacks but I have to manually maintain variable

scope
via session state or hidden variables. Is there a "best way".
Many thanks.

"fisab" wrote:

> Thanks a million for getting back to me. I've simplfied my problem below :-
>
> Partial Class TestVarScope_as px
> Dim varStr As String = "Not Set"
>
> Sub btnSet_Click(By Val sender As Object, ByVal e As

System.EventArg s)
> varStr = "String now set"
> End Sub
>
> Sub btnGet_Click(By Val sender As Object, ByVal e As

System.EventArg s)
> lblOutput.Text = varStr
> End Sub
> End Class
>
> When I click buttons 'btnSet' followed by 'btnGet', the output label

reads
> 'Not Set'.
>
> Any idea how I get around this problem ? It wasnt a problem in
ASPNet 1.1.
>
>
>
> "Brock Allen" wrote:
>
> > This should work. Can you give us some details on the error
message you're
> > seeing?
> >
> > -Brock
> > DevelopMentor
> > http://staff.develop.com/ballen
> >
> >
> >
> > > I apologise in advance for such a basic question, but I'm hoping
> > > someone will take the time to answer my question.
> > >
> > > In my code I define a Dataset :
> > >
> > > Partial Class Default_aspx
> > > Dim dsExcel As New DataSet
> > > I fill the Dataset as follows :
> > >
> > > Sub btnExcelList_Cl ick(ByVal sender As Object, ByVal e As
> > > System.EventArg s)
> > > <snip>
> > > myData.Fill(dsE xcel)
> > > And I try to interrogate it in another sub :-
> > >
> > > Sub btnImportLabinf o_Click(ByVal sender As Object, ByVal e As
> > > System.EventArg s)
> > > <snip>
> > > lblOutput.Text = CType(dsExcel.T ables(0).Rows.C ount, String)
> > > However, the scope of dsExcel is lost and I cannot retrieve the

data.
> > > It works in ASP.NET 1.1 where the whole class is defined in the

code > > > behind page.
> > >
> > > I would really appreciate it if someone answered me.
> > > Many thanks in advance,
> > > SteveB.
> >
> >
> >
> >


Nov 19 '05 #7
I wouldn't use either of them.

That scenario sounds tailor-made for the Cache object.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"fisab" <fi***@discussi ons.microsoft.c om> wrote in message
news:62******** *************** ***********@mic rosoft.com...
Appreciate the time you took to reply.
In your opinion is it more efficient to store a large dataset in viewstate
or as a session variables when posting back to the same page ?

"Patrice" wrote:
IMHO you were not doing the exact same thing in 1.1.

It's likely you were working in ASP.NET 1.1. on a control property. Here
this is just a member of your class and as such it is not handled by
viewstate.

And as the ASP.NET page lives just the time of the HTTP request, the
variable is then reset. Expected and usual behavior...
You could keep the sesssion variable or register this value explictely in
the page viewstate and so on...

Patrice
--

"fisab" <fi***@discussi ons.microsoft.c om> a écrit dans le message de
news:17******** *************** ***********@mic rosoft.com...
> I;ve solved it by using a session variable between the subs. Is that
> the

best
> way of handling variable postbacks. I assume that viewstate on controls
> is
> maintained between postbacks but I have to manually maintain variable

scope
> via session state or hidden variables. Is there a "best way".
> Many thanks.
>
> "fisab" wrote:
>
> > Thanks a million for getting back to me. I've simplfied my problem
> > below

:-
> >
> > Partial Class TestVarScope_as px
> > Dim varStr As String = "Not Set"
> >
> > Sub btnSet_Click(By Val sender As Object, ByVal e As

System.EventArg s)
> > varStr = "String now set"
> > End Sub
> >
> > Sub btnGet_Click(By Val sender As Object, ByVal e As

System.EventArg s)
> > lblOutput.Text = varStr
> > End Sub
> > End Class
> >
> > When I click buttons 'btnSet' followed by 'btnGet', the output label

reads
> > 'Not Set'.
> >
> > Any idea how I get around this problem ? It wasnt a problem in ASPNet

1.1.
> >
> >
> >
> > "Brock Allen" wrote:
> >
> > > This should work. Can you give us some details on the error message

you're
> > > seeing?
> > >
> > > -Brock
> > > DevelopMentor
> > > http://staff.develop.com/ballen
> > >
> > >
> > >
> > > > I apologise in advance for such a basic question, but I'm hoping
> > > > someone will take the time to answer my question.
> > > >
> > > > In my code I define a Dataset :
> > > >
> > > > Partial Class Default_aspx
> > > > Dim dsExcel As New DataSet
> > > > I fill the Dataset as follows :
> > > >
> > > > Sub btnExcelList_Cl ick(ByVal sender As Object, ByVal e As
> > > > System.EventArg s)
> > > > <snip>
> > > > myData.Fill(dsE xcel)
> > > > And I try to interrogate it in another sub :-
> > > >
> > > > Sub btnImportLabinf o_Click(ByVal sender As Object, ByVal e As
> > > > System.EventArg s)
> > > > <snip>
> > > > lblOutput.Text = CType(dsExcel.T ables(0).Rows.C ount, String)
> > > > However, the scope of dsExcel is lost and I cannot retrieve the

data.
> > > > It works in ASP.NET 1.1 where the whole class is defined in the
> > > > code
> > > > behind page.
> > > >
> > > > I would really appreciate it if someone answered me.
> > > > Many thanks in advance,
> > > > SteveB.
> > >
> > >
> > >
> > >


Nov 19 '05 #8

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

Similar topics

3
2789
by: phil | last post by:
I recently tried converting my asp.net 1.1 app to 2.0 in visual studio 2005 beta 2. I get several "type xxx is not defined" errors. It seems that some of my code file within my web application can no longer see the types defined in my asp.vb files. Here is a simple example:
16
2656
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
10
2452
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and load as a 3rd partial class. This would be handy so i can generate standard code into one of the partial classes, while having my custom code untouched
5
14346
by: Fernando Chilvarguer | last post by:
I'm sure this has come up before but I could not find any post on it. How can I read a variable or property that has been set on a ASPX page from inside a ASCX control. ASPX code: public partial class MyClass: System.Web.UI.Page { protected string _companyID;
2
1191
by: Jimmy | last post by:
This is a basic question. Does Page related member variable values only be set in the Page they are executed? Example code like below public partial class _Default : System.Web.UI.Page { string var = ""; protected void BtnSubmit_Click(object sender, EventArgs e) { if (Select.Checked)
6
5179
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick application working. However, when attempting to implement the solution, the AJAX calls weren't updating the screen like the examples were and seemed not to fire until after the long running process had completed. I found the only real...
20
4055
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This tells me if a variable has changed, give me the original and current value, and whether the current value and original value is/was null or not. This one works fine but is recreating the same methods over and over for each variable type. ...
2
1781
by: inadsad | last post by:
Good Day Group, Recently I started a small test project in C# VS 05 for learning purposes. I have a class and a form. I defined a property in a class with get/set and create an instance of class1 on form. The part I'm confused at is when trying to access Name property outside the click event it wouldn't work. Why is that? Should I create an instance after the InitializeComponent? and move all constants & variables to class1. I'd...
0
1446
by: Gary Herron | last post by:
Jacob Davis wrote: Yuck, YUCK, YUCK! You are breaking *so* many good-programming-practices, I hardly know where to start. First off: A python global is not what you think. There are *no* program wide globals. There are only module wide globals. Also, the "global isglobal" is absolutely meaningless as anything declared there is a (module level) global by definition.
0
9694
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10583
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9419
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7824
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7012
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5680
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4481
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 we have to send another system
2
4059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.