calling an ASP function

R

Roji. P. Thomas

Nooooooo

The onclick event works in the client side.

So you should write client side code for that.
 
S

Sylvain Lafontaine

Absolutely not.

The ASP code is executed on the server and nothing, except the result,
remain inside the HTML code when the page is displayed in the browser. If
you look at the source code from the browser, you will see that the function
setNarrowband() is totally missing. You need to use <script></script> tags
inside the HTML, with Javascript or VBScript code.

Also, when the HTML is displayed, you cannot write to it with a write
statement. It's something more complicated than that. Search Google for
DHTML (Dynamic HTML).

Try something like this instead:

<% response.write ........ %>

<script language=vbscript>
function SetNarrowBand()
msgbox "BROAD"
end function
</script>

There are other aspects, like the fact that the function setNarrowband may
or may not return a value and, if it returns a value, that this value can be
true of false. Different events, like onSubmit, onMouseOver, onClick, etc.,
may have a different response in each of these cases.

It will also explains why you will see something like
onClick="javascript:setNarrowband();" or
onClick="javascript:void(setNarrowband());" (Use javascript even if the
underlying function is coded in VBScript).

ASP.NET, which is not the same thing as ASP, bear some similitude to what
you have tried to do.

S. L.
 
R

Roland Hall

Ãéþñãïò ÓôÜèçò said:
The following code is supposed to display a message when pressing the
button?

<%
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"">")

Function setNarrowband()
response.write("BROAD")
End Function
%>

<%@ Language=VBScript %>
<%
response.write("<script type=""text/javascript"">" & vbCrLf & _
"function setNarrowband() {" & vbCrLf & _
" document.write(""BROAD"");" & vbCrLf & _
" }" & vbCrLf & _
"</script>" & vbCrLf)
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"" />")
%>

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
 
Ã

Ãéþñãïò ÓôÜèçò

Well I'm a newbie in ASP but still I can't understand the reason to get an
error message when I click on the button.
The following code is supposed to display a message when pressing the
button?

<%
response.write("<input type=""button"" name=""radio_connection""
value=""narrowband"" onClick=""setNarrowband()"">")

Function setNarrowband()
response.write("BROAD")
End Function
%>
 
A

Aaron Bertrand - MVP

Performing a document.write after the page has loaded (since a user can't
really click on a button until the page has been rendered) is going to to
unpredictable things on different browsers. Also, where on the page is this
going to go? At the end?

I think DHTML would be the right angle (but again, the original poster
should go to a client-side group for the technical details).

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
 
R

Roland Hall

Aaron Bertrand - MVP said:
Performing a document.write after the page has loaded (since a user can't
really click on a button until the page has been rendered) is going to to
unpredictable things on different browsers. Also, where on the page is this
going to go? At the end?

I think DHTML would be the right angle (but again, the original poster
should go to a client-side group for the technical details).

I agree with all points you made. This example replaces the page with only
the text written. It is not a viable solution but it was an answer of how
to make, what he wanted, functional.

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
 

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,141
Messages
2,570,817
Members
47,362
Latest member
ChandaWagn

Latest Threads

Top