Calling code-behind from javascript

N

nams

Hi Frnds,

Say I have vb code like this:

Public Sub ll()
MsgBox("heLOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", MsgBoxStyle.OkOnly)
End Sub

The following script runs as soon as the page loads, no matter what
the value of b is. why is it so ?

<script type="text/javascript" language="javascript">
function ss()
{
var b = 1;
if(b==2)
{
<% ll() %>;
}
}
</script>

I want the code to get executed only if the if-condition is true and
also only when i call the script - i mean not as soon as the page
loads. Please help me.

Thanks,
Nams here
 
D

David Mark

Hi Frnds,

Say I have vb code like this:

 Public Sub ll()
        MsgBox("heLOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", MsgBoxStyle.OkOnly)
    End Sub

This is not a VB.NET group. But as I am somewhat familiar with .NET,
I can tell you that you are very confused (not an uncommon state
among .NET developers.)

Try searching for a VB.NET group.

[snip]
 
E

Evertjan.

nams wrote on 26 feb 2008 in comp.lang.javascript:
Hi Frnds,

Say I have vb code like this:

Public Sub ll()
MsgBox("heLOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", MsgBoxStyle.OkOnly)
End Sub

The following script runs as soon as the page loads, no matter what
the value of b is. why is it so ?

VB does not run on a server, nor on a browser,
vb is a compiling language.

VBscript can run on a server under ASP,
or on an IE browser on the client.

You seam to mean this to be serverside vbs code, as you show the <% %>
below.

Calling MsgBox() on a server in ASP-vbs is futile, as many servers do not
evn have a screen, and ASP has no rights displaying on the server, and if
you have 20 or 1000 concurrent users, whose MsgBox would it be that
should be displayed on the server's possibly absent dislay?

<script type="text/javascript" language="javascript">

language="javascript" can be left out.
function ss()
{
var b = 1;
if(b==2)
{
<% ll() %>;

When the clientside code is executed on the browser, the server is
already finished with it.

Only any resulting text stream is inserted for the browser to be executed
ON THE CLIENT. Your serverside sub does NOT produce any clientside code.
}
}
</script>

I want the code to get executed only if the if-condition is true and

The if condition in your code above is never true.
also only when i call the script - i mean not as soon as the page
loads. Please help me.

You can call a NEW serverside page from the client/browser by using the
Ajax technique, but even then displaying a MsgBox on the server display
seems not usefull and is impossible.
Thanks,
Nams here

Please rethink the difference between serverside script execution and
clientside script execution.
 
D

David Mark

nams wrote on 26 feb 2008 in comp.lang.javascript:





VB does not run on a server, nor on a browser,
vb is a compiling language.

It does in VB.NET, which is slightly modified version of VB6 running
on a Web server.
VBscript can run on a server under ASP,
or on an IE browser on the client.

You seam to mean this to be serverside vbs code, as you show the <% %>
below.

Calling MsgBox() on a server in ASP-vbs is futile, as many servers do not
evn have a screen, and ASP has no rights displaying on the server, and if
you have 20 or 1000 concurrent users, whose MsgBox would it be that
should be displayed on the server's possibly absent dislay?

Yes, like most VB -> VB.NET converts, the OP is very confused about
Web-related concepts.
language="javascript" can be left out.


When the clientside code is executed on the browser, the server is
already finished with it.

Only any resulting text stream is inserted for the browser to be executed
ON THE CLIENT. Your serverside sub does NOT produce any clientside code.
Exactly.



The if condition in your code above is never true.

Clearly the OP is trying to come up with a way to stop the messagebox
from appearing. I assume he is developing on the server and has
permissions set to allow the messagebox to appear (possible in VB.NET
I think.) If this is the case, it compounds the confusion by making
it appear that the messagebox is being shown by IE.
You can call a NEW serverside page from the client/browser by using the
Ajax technique, but even then displaying a MsgBox on the server display
seems not usefull and is impossible.

Certainly not useful, but I don't think it is impossible.

[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top