Solved

Calling server side function from client side

Posted on 2002-06-11
7
243 Views
Last Modified: 2012-05-04
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
Comment
Question by:sanjuo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Expert Comment

by:choroque
ID: 7071679
<%@ 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
 
LVL 12

Expert Comment

by:Wouter Boevink
ID: 7072051
You cannot execute a function on the server without a roundtrip to the server.
0
 
LVL 11

Accepted Solution

by:
ASPGuru earned 30 total points
ID: 7072160
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:sanjuo
ID: 7072985
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
 
LVL 3

Expert Comment

by:dragosh
ID: 7073009
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
 
LVL 11

Expert Comment

by:ASPGuru
ID: 7073169
XMLHTTP will only work in IE and NS6 maybe...

is this ok for you?

ASPGuru
0
 
LVL 4

Expert Comment

by:Wakie
ID: 9142969
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question