Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onclick event to call a vb sub

Status
Not open for further replies.

bryant89

Programmer
Nov 23, 2000
150
CA
I have an image that I need to call a vb method on its onclick event. Its simple to do with js. just like this
onClick="jsmethod();"

But how do you tell it to call a vb method.
I tried doing this
onClick="vbmethod();"
but that will not work.

Any suggestions will help.
New to asp and interdev.
 
Yes Bryant all you need to do is this.

<SCRIPT LANGUAGE=vbscript>
function vbfunction()

alert(&quot;Thanks yo&quot;)

end function
</SCRIPT>

then in the image tag you simply put this for the onclick event
onClick=vbfunction();
 
That's fine if you want to just pop up an alert message but lets say you wanted to call a method within a script that is set to run at server side? How do you do that.

So like this here
<SCRIPT LANGUAGE=vbscript>
function vbfunction()

dostuff()

end function
</SCRIPT>

<SCRIPT ID=serverEventHandlersVBS LANGUAGE=vbscript RUNAT=Server>

Sub dostuff()
...stuff in here to do
end sub
</SCRIPT>

Yes that's right it doesnt work. Same language but run in different places. So when I try to call the method dostuff() from the vbscript that is not set to run at server it will not work.
How do I accomplish this or can I?
 
What the heck is going on with this thread! Are you talking to yourself bryant?

What gives?


> say you wanted to call a method within a script that is set to run at server side?

That has nothing to do with the language of the script. The main issue is client vs. server. You just cannot run a server side script from inside a client side script without using some component that would provide a connection to the server code.

Didn't we discuss this last week, or are the holidays really getting to me? :)

-pete
 
Ya I know. We went through this. But I am asking is there a way to call that somehow or how do I provide this connection from the client to the server side code. I tried putting asp tag code within the client side code and it worked but it just called the method right away and ignored everything else.

I want to do what I showed in my example I want to call the dostuff() method that is in the serverside script from the nonserverside script. Is there any way to do it?
 
> But I am asking is there a way to call that somehow

No. Your client code is executing in the browser. It cannot call a function that exists and runs on the server.

To make code run on the server the browser must request the resource from the server that the code runs in. Now I will show you a simple method that will accomplish what I am describing however depending on what your server code does and what your goal is it may not apply to your problem.
<%@ language=javascript %>

<script language=javascript>
function onclickTheImage(){
document.form1.theyClickedTheImage.value = &quot;1&quot;;
document.form1.submit();
}
</script>

<form name=&quot;form1&quot; id=&quot;form1&quot; action=&quot;myAspThatHasMyServerFunctionThatIWantToRun.asp&quot;>
<input type=&quot;hidden&quot; name=&quot;theyClickedTheImage&quot; id=&quot;theyClickedTheImage&quot; value=&quot;0&quot;>

</form>

<script language=vbscript runat=server>
function doMyThing()
'do whatever
end function
</script>

<%
var nTheyClickedTheImage = Request(&quot;theyClickedTheImage&quot;);
if ( isNaN(nTheyClickedTheImage))
nTheyClickedTheImage = 0;

if ( 1 == nTheyClickedTheImage )
doMyThing(); // call the vb function
%>

Hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top