473,386 Members | 1,798 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,386 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 4263
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.