Calling a function from a button...easy, right?!

S

ScooterMX

I just have a function that does some sql stuff. When I run this I get an
object expected error on the <input type="button"... line
Does anyone have a suggestion?
This is written for IE only - it's an internal tool...

Here is the code that fails.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>tool</title>

<%
Function flushActivity
Dim oConn, cSql
cSql= "UPDATE activity SET Content= '' WHERE Class_Number = 2"
set oConn = Server.CreateObject("ADODB.connection")
oConn.Open Session("DSN")
oConn.Execute(cSql)
Response.write("executing: " & cSql & "<br>")
oConn.Close
set oConn = nothing
End Function
%>

</head>
<body>

<form>
<input type="button" value="Flush Activity" onclick="flushActivity()">
</form>
</body>
</html>
 
R

Ryan Trudelle-Schwarz

I just have a function that does some sql stuff. When I run this I get
an
object expected error on the <input type="button"... line
Does anyone have a suggestion?
This is written for IE only - it's an internal tool...
Here is the code that fails.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>tool</title>
<%
Function flushActivity
Dim oConn, cSql
cSql= "UPDATE activity SET Content= '' WHERE Class_Number = 2"
set oConn = Server.CreateObject("ADODB.connection")
oConn.Open Session("DSN")
oConn.Execute(cSql)
Response.write("executing: " & cSql & "<br>")
oConn.Close
set oConn = nothing
End Function
%>

</head>
<body>
<form>
<input type="button" value="Flush Activity" onclick="flushActivity()">
</form>
</body>
</html>

Do you want this to execute on the client or the server? Right now, your
script block is server code while your button's onclick handler is client
side.
 
S

ScooterMX

Ryan Trudelle-Schwarz said:
Do you want this to execute on the client or the server? Right now, your
script block is server code while your button's onclick handler is client
side.

Interesting... the function accesses a sql database, which is server side.
I assumed that the function was client side. whats the best way to go about
this, given that the db is on the server?

(thanks SO much in advance!)
 
R

Ryan Trudelle-Schwarz

Ryan Trudelle-Schwarz said:
Interesting... the function accesses a sql database, which is server
side. I assumed that the function was client side. whats the best way
to go about this, given that the db is on the server?

(thanks SO much in advance!)

IIRC, the easiest method is going to be to add a Runat="server" to the button
tag, in which case the button should post back and call the method when clicked.
In case the input type="button" is not wired up to do that, you can use a
<asp:button in its place and get the same functionality (just change the
tag name and change value attribute to text and it should be good).
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top