javascript and asp.net
I have a program which runs a lot of batch files so I have built a progress bar by javascript which shows the progress. After I run every batch file I call the javascxript function and the function increases the bar by 1 point. This works in asp so I tried to convert it to asp.net I do something like this:
-------------------
mystring="<script language='javascript'>imgLoaded();" & chr(60) &"/script>"
run the first batch
RegisterStartupScript("JString1", myString.ToString())
run the second batch
RegisterStartupScript("JString2", myString.ToString())
and so on.......
-------------------
when I do this all the batches are run and then the javascript function is called.Thats is not what I want...I want to run the batch and then call the javascript function.
Do you know how I can do this?
thanks
[876 byte] By [
cengo] at [2007-11-11 6:50:06]

# 1 Re: javascript and asp.net
See if this helps:
http://www.eggheadcafe.com/articles/20050108.asp
# 2 Re: javascript and asp.net
thanks... I am going to look into that
cengo at 2007-11-11 23:15:13 >

# 3 Re: javascript and asp.net
So there is no way of calling javascript functions immediately when the .net code is running.why does javascript function call has to wait till the .net code is over?
cenk
cengo at 2007-11-11 23:16:17 >

# 4 Re: javascript and asp.net
Because JavaScript code runs in the user's browser, and ASP.NET code runs on the server. There's no way for code on the server to execute code in the user's browser.
# 5 Re: javascript and asp.net
but I can do what I want with asp...
run asp code
call the javascript function
run asp code
call the javascript function
and so on......
why can not I do it with asp.net?
cengo at 2007-11-11 23:18:10 >

# 6 Re: javascript and asp.net
I don't see how that can work, even in ASP. Can you post a simple page that demonstrates this technique?
# 7 Re: javascript and asp.net
ok here is an example page:
http://www.imlab.psu.edu/aspnet/forest/progress.asp
you cann see the javascript contents of this page and the only asp content of this page is :
<%
Response.buffer = false
Server.ScriptTimeout = 400
for g=1 to 648
Response.write "<script>imgLoaded();</script>"
Next
%>
and this works!!!or am I missing something?
cengo at 2007-11-11 23:20:20 >

# 8 Re: javascript and asp.net
The difference is that ASP code is interpreted script, whereas ASP.NET is compiled code.
# 9 Re: javascript and asp.net
when I use the "<%" in asp.net then I call the functions...Does that mean that whatever is in "<%" tags in asp.net is being interpreted but not being compiled?
If it s then I should minimize using the "<%" tags right?
cengo at 2007-11-11 23:22:14 >

# 10 Re: javascript and asp.net
No, all server-side code in ASP.NET is compiled.
# 11 Re: javascript and asp.net
so how come the code works when I put the
Response.write ("<script language='javascript'>imgLoaded();</script>")
line in the "<%" blocks
and it does not work when I put it in the "sub Page_Load" method?
cengo at 2007-11-11 23:24:20 >

# 12 Re: javascript and asp.net
If it works when you put the code in <% %> blocks, then why are you asking for help? ;-)
# 13 Re: javascript and asp.net
because I am wandering why it works that way and not the other way?I thought I was doing something wrong....because this should not really work...net is server side and compiled and javascript is client side so how is it possible that they work together?
also I might have problems with using codebehind if I use "<%" tags..am I not right?
cengo at 2007-11-11 23:26:25 >

# 14 Re: javascript and asp.net
When you do response.write, it is writing to your browser. so when your page is loaded it every thing in WRITE is put at the top of the file. so they are not exactly work together...it is just that you are writing your exact browser code/script at the server.
In the ASP sample, ASP and JavaScript are not working together but ASP code is creating the javascript which is then called over and over by the browser. In other words, if you had a lot of code before the response.write..it would still finish everything on the server and then write the script. Consequently you will see the image bar but only after every thing is done.