473,400 Members | 2,163 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,400 software developers and data experts.

sharing variables between methods

here is some test code i've set up trying to figure out how to share
variables between two different methods.

__________________________________________________

Public Class test
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "
#End Region

Public Shared testvar As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
testing.Text = testvar
End Sub

Sub makevar()
testvar = "this is a test"
DataBind()
End Sub

End Class

__________________________________________________

this is not working... can someone tell me what i'm doing wrong or if
this is even possible?

thanks,
Jeff

Nov 19 '05 #1
6 1528
Is anything actually calling 'makevar'? It doesn't look like it.

"tfsmag" <tf****@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
here is some test code i've set up trying to figure out how to share
variables between two different methods.

__________________________________________________

Public Class test
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "
#End Region

Public Shared testvar As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
testing.Text = testvar
End Sub

Sub makevar()
testvar = "this is a test"
DataBind()
End Sub

End Class

__________________________________________________

this is not working... can someone tell me what i'm doing wrong or if
this is even possible?

thanks,
Jeff

Nov 19 '05 #2
You'll want to avoid the Shared keyword then - it will share the
variable among all instances of your class (only one testvar in the
entire application no matter how many test classes exist).

From a high level point of view, what is it you need to accomplish?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 16 Jun 2005 12:59:15 -0700, "tfsmag" <tf****@gmail.com> wrote:
here is some test code i've set up trying to figure out how to share
variables between two different methods.

_________________________________________________ _

Public Class test
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "
#End Region

Public Shared testvar As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
testing.Text = testvar
End Sub

Sub makevar()
testvar = "this is a test"
DataBind()
End Sub

End Class

_________________________________________________ _

this is not working... can someone tell me what i'm doing wrong or if
this is even possible?

thanks,
Jeff


Nov 19 '05 #3
Web application is stateless.So If you want to get testvar variable in your
page_load method,You must set testvar's value before using.

or you can declare this varable is static.

or set testvar in your oninit method.It look like this:
protected override void OnInit(EventArgs e){
.....
testvar = "this is a test";
}

"tfsmag" wrote:
here is some test code i've set up trying to figure out how to share
variables between two different methods.

__________________________________________________

Public Class test
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "
#End Region

Public Shared testvar As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
testing.Text = testvar
End Sub

Sub makevar()
testvar = "this is a test"
DataBind()
End Sub

End Class

__________________________________________________

this is not working... can someone tell me what i'm doing wrong or if
this is even possible?

thanks,
Jeff

Nov 19 '05 #4
scott,

what i'm trying to accomplish is in a page where i have a calendar
control... on the DayRenderEventArgs method i've created i want to
capture the current month and year shown, and set a variable in that
method that i can carry over to the bindgrids() method so i can pull
all records within a daterange as determined by the 'month shown' into
a datagrid.

Nov 19 '05 #5
I think you should use viewstate for your question.
For example:
private string testvar{
set{
this.ViewState["testvar"] = value;
}
get{
return (string)this.ViewState["testvar"];
}
}

"tfsmag" wrote:
scott,

what i'm trying to accomplish is in a page where i have a calendar
control... on the DayRenderEventArgs method i've created i want to
capture the current month and year shown, and set a variable in that
method that i can carry over to the bindgrids() method so i can pull
all records within a daterange as determined by the 'month shown' into
a datagrid.

Nov 19 '05 #6
You could take the Shared keyword out - the variable approach should
work for you.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On 16 Jun 2005 19:11:11 -0700, "tfsmag" <tf****@gmail.com> wrote:
scott,

what i'm trying to accomplish is in a page where i have a calendar
control... on the DayRenderEventArgs method i've created i want to
capture the current month and year shown, and set a variable in that
method that i can carry over to the bindgrids() method so i can pull
all records within a daterange as determined by the 'month shown' into
a datagrid.


Nov 19 '05 #7

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

Similar topics

42
by: Dan | last post by:
Hello, I have trouble with class calling. I am calling getvolume() with succes in the function CreateCircle but it do not want to call it in ShowCircle() function. I am staying in the same...
4
by: Cowboy \(Gregory A. Beamer\) | last post by:
Background: ------------- The idea started as a single sign on type of application. Having tested it before, I knew we could institute single sign on using the same Authentication Cookie name (in...
3
by: Chris Dunaway | last post by:
How can a class be shared between a web service and a client that consumes the web service? Suppose I have a Class Libraray with the following simple class: Public Class SimpleClass Private...
3
by: darrel | last post by:
This is something I should know, but I don't. Say I have this: Function dim variable1 dim variable2 do stuff with the variables
3
by: Selden McCabe | last post by:
I have an old ASP project, and I'm adding some functionality in ASP.Net. I stuff some information into Session variables in the ASP page, then redirect to the ASP.Net page. But when I pull up...
2
by: bhawna.email | last post by:
Can we share a variable between 2 methods withour making the variable as static?
1
by: David Belohrad | last post by:
Dear All, could someone give a hint? I'd like to share the resources as follows: A shared class which works as counter of number of shared resources: class Shared { public: Q_PCBShared()...
6
by: awhan.iitk | last post by:
I have a set of variables that I want to share across mulitple c++ files. I was using the extern method so far. Is there any other way to do the same. The variables are not constants and I get the...
45
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
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...
0
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...

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.