473,399 Members | 4,254 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,399 software developers and data experts.

JavaScript won't show ASP.NET var current value

I have javascript code that does an alert on a public asp.net var...
alert("<%=strMessage%>");
The code runs whenever my ajax related code completes.

I declared the public var like this...
Public strMessage as string = "PUBLIC MESSAGE"

In my code I changed the variable but when the alert runs it always has the
original value, even though the var has been updated.

Any ideas why?
Aug 17 '08 #1
4 1991
Thanks for teh info. Instead of using a public var I tried using a label on
teh form so that I could see the value.

I tried to 'alert' the value of teh label but it's not showing until after
teh js runs (then the label is set).

Basically here's all my js...
<script type="text/javascript">
//add event handlers to the search UpdatePanel
Sys.WebForms.PageRequestManager.getInstance().add_ beginRequest(startRequest);
Sys.WebForms.PageRequestManager.getInstance().add_ endRequest(endRequest);

function startRequest(sender, e) {
//disable controls during the AJAX call
document.getElementById("<%=Panel1.ClientID%>").di sabled = true;
}

function endRequest(sender, e) {
//re-enable controls once the AJAX call has completed
document.getElementById("<%=Panel1.ClientID%>").di sabled =
false;
if
(document.getElementById("<%=lblPublicMessage.Clie ntID%>").text != "")
alert(document.getElementById("<%=lblPublicMessage .ClientID%>").text);
}
</script>

This is an ajaxified webform. When I click my 'update db' button it runs
for a while (hence the js code to disable all the controls on the webform.)
In the vb.net code I set lblPublicMessage with a status. I would think it
would be between StartRequest and EndRequest.

When I tried to read lblPublicMessage it's either undefined or ''. After
the alert the label is updated.

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:O0**************@TK2MSFTNGP06.phx.gbl...
Well, the first thing I would do (if you haven't already) is do a View
Source to see if what you expected is what is really being sent to the
browser. Also, and this is just a personal preference, I do not completely
trust using the <%= %tags, so you may want to try using the methods
of Page.ClientScript instead. At what point do you change the value of
strMessage? One of the situations that has always been a real pain for me
when debugging in many cases is when the problem is caused by when I do
something. Hopefully some of this will help, good luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Cirene" <ci****@nowhere.comwrote in message
news:Ok**************@TK2MSFTNGP06.phx.gbl...
>>I have javascript code that does an alert on a public asp.net var...
alert("<%=strMessage%>");
The code runs whenever my ajax related code completes.

I declared the public var like this...
Public strMessage as string = "PUBLIC MESSAGE"

In my code I changed the variable but when the alert runs it always has
the original value, even though the var has been updated.

Any ideas why?


Aug 17 '08 #2
Well, the first thing I would do (if you haven't already) is do a View
Source to see if what you expected is what is really being sent to the
browser. Also, and this is just a personal preference, I do not completely
trust using the <%= %tags, so you may want to try using the methods of
Page.ClientScript instead. At what point do you change the value of
strMessage? One of the situations that has always been a real pain for me
when debugging in many cases is when the problem is caused by when I do
something. Hopefully some of this will help, good luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Cirene" <ci****@nowhere.comwrote in message
news:Ok**************@TK2MSFTNGP06.phx.gbl...
>I have javascript code that does an alert on a public asp.net var...
alert("<%=strMessage%>");
The code runs whenever my ajax related code completes.

I declared the public var like this...
Public strMessage as string = "PUBLIC MESSAGE"

In my code I changed the variable but when the alert runs it always has
the original value, even though the var has been updated.

Any ideas why?

Aug 17 '08 #3
re:
!In my code I changed the variable but when the alert runs it always
!has the original value, even though the var has been updated.
!Any ideas why?

Unless you postback the page, the Javascript variable can't be updated at the server.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Cirene" <ci****@nowhere.comwrote in message news:Ok**************@TK2MSFTNGP06.phx.gbl...
>I have javascript code that does an alert on a public asp.net var...
alert("<%=strMessage%>");
The code runs whenever my ajax related code completes.

I declared the public var like this...
Public strMessage as string = "PUBLIC MESSAGE"

In my code I changed the variable but when the alert runs it always has the original value, even though the var has
been updated.

Any ideas why?

Aug 17 '08 #4
So in an ajaxified page how can I do this? I do see that the label changes
by the vb.net code, but it's after the javascript code runs...

"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
re:
!In my code I changed the variable but when the alert runs it always
!has the original value, even though the var has been updated.
!Any ideas why?

Unless you postback the page, the Javascript variable can't be updated at
the server.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Cirene" <ci****@nowhere.comwrote in message
news:Ok**************@TK2MSFTNGP06.phx.gbl...
>>I have javascript code that does an alert on a public asp.net var...
alert("<%=strMessage%>");
The code runs whenever my ajax related code completes.

I declared the public var like this...
Public strMessage as string = "PUBLIC MESSAGE"

In my code I changed the variable but when the alert runs it always has
the original value, even though the var has been updated.

Any ideas why?


Aug 17 '08 #5

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

Similar topics

12
by: Ali | last post by:
I have the following web page with a script in it. <html> <head> <title>Make Your Own Objects test</title> <script>
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
5
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE...
1
by: Diz | last post by:
Hi, Can anybody tell me why my php script wont run properly unless i put it in a page all on its own? Is it antisocial? Does it want to be alone? I have put it in a page with background and links to...
3
by: TS | last post by:
we publish our exceptions to email at work and include the form's vlaues to help debug in production. Since the control wont' appear if it is empty, how can i access it to show the controls wiht a...
3
by: Arthur Dent | last post by:
Hello All,.. I have some settings stored in the project settings which show up under My.Settings. ... All works fine. Now, I wanted to change the value of one of these settings, so I went...
5
by: moni | last post by:
Hi.. I am trying to use javascript for google maps display. If I call the javascript function from my aspx file I use: <input type="text" id="addresstext" value="Huntington Avenue,...
0
by: qutspan | last post by:
When I create taskbox on the form the line beside the box wont show up. it show up untill I have MouseEnter event occur. Also when I have 2 taskbox on the form it does draw the line around the...
1
by: WestyCHC | last post by:
Morning all from a newbie. I have recently written an automation program (my first ever program) for testing and now I am trying to read XML data and assign the values to variables (rather than...
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
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
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
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...
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.