473,757 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P age

#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.EventArg s) 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 1544
Is anything actually calling 'makevar'? It doesn't look like it.

"tfsmag" <tf****@gmail.c om> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.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.P age

#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.EventArg s) 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.c om> 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.P age

#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.EventAr gs) 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(EventArg s 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.P age

#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.EventArg s) 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 DayRenderEventA rgs 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.Vi ewState["testvar"];
}
}

"tfsmag" wrote:
scott,

what i'm trying to accomplish is in a page where i have a calendar
control... on the DayRenderEventA rgs 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.c om> wrote:
scott,

what i'm trying to accomplish is in a page where i have a calendar
control... on the DayRenderEventA rgs 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
3201
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 class. I thought that was the point of encapsulation. When the function ShowCircle() is called I get very large number -1.07374e+008 can anyone help me ?
4
2052
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 this case "AuthenticationCookie" -- yeah, original, I know) and the same machine keys for the applications. <authentication mode="Forms"> <forms name="AuthenticationCookie" path="/" loginUrl="login.aspx" protection="All" timeout="10" />
3
1369
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 _AnInteger As Integer Public Property AnInteger As Integer Get
3
1742
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
1689
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 the session variables, they are empty! Is it possible to share session variables this way? Thanks,
2
1255
by: bhawna.email | last post by:
Can we share a variable between 2 methods withour making the variable as static?
1
2025
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() : n_count (1) { };
6
1730
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 values during run time.
45
3009
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 clsData Private m_objSQLClient As clsSQLClient Private m_objUsers As clsUsers
0
9487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7285
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
6556
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
5168
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
3828
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
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
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.