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

Variable scope in ascx file

Hi,

Could someone please help?! I am declaring a global variable in an ascx
file...

<%@ Control Language="VB" runat="server" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@Import namespace="System.Web.Mail"%>

<script language="VB" runat="server">
Dim strDriver as String
..
..

...then I assign this variable a value in a sub...

Sub edit_Clicked(sender as Object, e As DataGridCommandEventArgs)

strDriver = CType(E.Item.FindControl("lblDriverName"), Label).Text
..
..
.. in another sub, I am trying to retrieve the stored value... but it's
coming up blank...

Sub update_Clicked(ByVal sender as Object, ByVal e As
DataGridCommandEventArgs)

strText = "Driver name is " & strDriver & ".<br/>"
Probably something simple! I am new to ASP.NET. Much appreciated!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
1 4273
The page, and hence the user control in it, and hence all the variables in
the user controls - are all recreated on every request. This is because
HTTP is stateless, and so there is no other choice.

Because everything is reinitialized from scratch - your variable is empty
every time a new instance is created. So setting its value on one postback,
will not persist on another one.

You will need to find another way to store this information, such as
viewstate or session.

"John Mason" <jo**@wollondilly.org> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

Could someone please help?! I am declaring a global variable in an ascx
file...

<%@ Control Language="VB" runat="server" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@Import namespace="System.Web.Mail"%>

<script language="VB" runat="server">
Dim strDriver as String
.
.

..then I assign this variable a value in a sub...

Sub edit_Clicked(sender as Object, e As DataGridCommandEventArgs)

strDriver = CType(E.Item.FindControl("lblDriverName"), Label).Text
.
.
. in another sub, I am trying to retrieve the stored value... but it's
coming up blank...

Sub update_Clicked(ByVal sender as Object, ByVal e As
DataGridCommandEventArgs)

strText = "Driver name is " & strDriver & ".<br/>"
Probably something simple! I am new to ASP.NET. Much appreciated!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2

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

Similar topics

2
by: John Smith | last post by:
With the code below, is it possible to access "strTemp" in "WebUserControl.ascx"? I always receive the error that "strTemp" is not available. As a workaround, I am using a Session variable, but I...
14
by: rahul8143 | last post by:
hello, To limit scope of a variable in a single file that is part of a large project that have several C files we use static variable right?then to limit any variable to function scope it should...
4
by: Jason Shohet | last post by:
A label on an ascx control has a corresponding declaration in the c# code-behind page. I was curious what would happen if I made that declaration 'PRIVATE' instead of 'PROTECTED'. The only things...
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
1
by: John Mason | last post by:
Hi, Could someone please help?! I am declaring a global variable in an ascx file... <%@ Control Language="VB" runat="server" %> <%@ import Namespace="System.Data" %> <%@ import...
1
by: Darrel | last post by:
Is it possible to set a variable in one UserControl that another UserControl can read? For example: page.aspx navigationControl.ascx pageBanner.ascx the navigation control builds a menu...
1
by: Darrel | last post by:
I've figured out how to read a variable in one ASCX file from another. Works great. I now would like to have one ASCX file set a variable in its parent ASPX or another ASCX file. Can that be...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
3
by: SRoubtsov | last post by:
Dear all, Do you know whether ANSI C (or some other dialects) support the following: * a variable name coincides with a type name, * a structure/union field name coincides with a type name in...
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...
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
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...
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
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,...
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.