Newbie Question running a subroutine with a button

N

NTGod

I have a question I have been trying to run this asp page with a
subroutine. I have been trying to have you click on a button and run a
subroutine on the server then return a variable. Also my next try will
be to get and input from a test box into the subroutine and return
data/variable.

Here is the sample hello.asp page:

The page should just have a hello button and when clikced display hello
on the page.

<html>
<head>
<title>hello</title>
</head>
<%
Sub hello()
strHello = "hello"
End Sub
%>
<body>
<input id=Button type=button value="hello" Name="ehlo"
Language="VBScript" onClick="hello()">
<%= strHello %>
</body>
 
T

Tim Williams

If you want to run code on the server from a page loaded on the client
then you will have to make a request to the server. Your page does
not exist simultaneously on both the server and the client. Normal
method would be to do a POST or GET using a form in the page.

If you don't want the page to refresh, you can use XMLHTTP or
something similar, but this may restrict your target audience as far
as browser compatibility goes.
http://developer.apple.com/internet/webcontent/xmlhttpreq.html

Tim.
 
H

Hal Rosser

NTGod said:
I have a question I have been trying to run this asp page with a
subroutine. I have been trying to have you click on a button and run a
subroutine on the server then return a variable. Also my next try will
be to get and input from a test box into the subroutine and return
data/variable.

Here is the sample hello.asp page:

The page should just have a hello button and when clikced display hello
on the page.

<html>
<head>
<title>hello</title>
</head>
<%
Sub hello()
strHello = "hello"
End Sub
%>
<body>
<input id=Button type=button value="hello" Name="ehlo"
Language="VBScript" onClick="hello()">
<%= strHello %>
</body>

In your example - you should make the sub hello() into a client-side
javascript function - then it would work as expected.
Remember - client-side code runs at the users machine in the browser - and
that code is in <script> tags.
but ASP runs on the server - then sends the page it creates to the user .
 

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

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,059
Members
48,769
Latest member
Clifft

Latest Threads

Top