473,321 Members | 1,708 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,321 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 4239
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.