• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Calling server side function from client side

How to call server-side function from client side without posting response. Sample code below

<%@ Language=VBScript %>
<%
function ShowMe()
  Response.write "Hello world!!!"
end function
%>
<html>
<body>
<form name="Form1" method=post action=myasp.asp>
<input type="button" name="load" value="load" onclick="javascript:ff();">
</form>
</body>
</html>
<script LANGUAGE="JavaScript">
function ff()
{
     eval("<%zz = ShowMe()%>")
     alert(zz);
}
</script>
0
sanjuo
Asked:
sanjuo
1 Solution
 
choroqueCommented:
<%@ Language=VBScript %>
<%
function ShowMe()
 Response.write "Hello world!!!"
end function
%>
<html>
<body>
<form name="Form1" method=post action=myasp.asp>
<input type="button" name="load" value="load" onclick="javascript:ff();">
</form>
</body>
</html>
<script LANGUAGE="JavaScript">
function ff()
{
    <%zz = ShowMe()%>
    alert('<%=zz%>');
}
</script>
0
 
Wouter BoevinkCommented:
You cannot execute a function on the server without a roundtrip to the server.
0
 
ASPGuruCommented:
choroque, your code will not work...

sanjuo, wboevink is right, actually...
you can't really...

of course i can make your code work the way you expect it, but only by calling the function _before_ sending the data to the browser... have a look at this:

<%@ Language=VBScript %>
<%
function ShowMe()
 ShowMe = "Hello world!!!"
end function
%>
<html>
<body>
<form name="Form1" method=post action=myasp.asp>
<input type="button" name="load" value="load" onclick="javascript:ff();">
</form>
</body>
</html>
<script LANGUAGE="JavaScript">
function ff()
{
    alert("<%=ShowMe()%>");
}
</script>

ASPGuru
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sanjuoAuthor Commented:
First thank all for your efforts,

ASPGuru,

I want the server-side function get executed when you press button not before that.

I saw some code which uses xmlhttp service to overcome this problem. Really I did not understand that code and I lost that link also. I will try to find that link. Let you know.
0
 
dragoshCommented:
hi there

here is a simple example of using XMLHTTP :


demo.asp
========

<%@ Language=VBScript %>
<HTML>
<HEAD>
<script language="javascript">
<!--
function doAction()
{
     var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
     xmlhttp.open("POST", "action.asp?action=X", false);
     xmlhttp.send("text");
     mydiv.innerHTML = xmlhttp.Responsetext;
}

// -->
</script>
</HEAD>
<BODY>

<P>xmlhttp demo</P>


<input type="button" name="btnAction" value="action" onclick="javascript:doAction();">
<div id="mydiv"></div>

</BODY>
</HTML>

action.asp
==========

<%@ Language=VBScript %>
<%

If Request.QueryString("action") = "X" Then
     Response.Write Request.ServerVariables("REQUEST_METHOD")
Else
     Response.Write Request.TotalBytes
End If
%>


i hope this will help
0
 
ASPGuruCommented:
XMLHTTP will only work in IE and NS6 maybe...

is this ok for you?

ASPGuru
0
 
WakieCommented:
It appears this question has been abandoned.

I will leave a recommendation in the Cleanup topic area that this question will be:

- Question PAQ'd and points to ASPGuru -

Please leave any comments here within the next seven days.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Wakie,
EE Cleanup Volunteer.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now