Solved

Call ASP.NET sub from javascript

Posted on 2004-03-30
5
596 Views
Last Modified: 2012-05-04
Is it possible to do this? If not, is there a workaround (i.e. a button just for that purpose and javascript calling button.click)?

Thanks
0
Comment
Question by:gromul
  • 2
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
ill earned 300 total points
ID: 10712301
not sure if this is,what you want, but...
this code in <body> section
--------------------

<span onclick='callASPSub("testme( 21, 666)")'>execute ASP<span>
<div id='aspdiv' />
<script type='text/javascript">
function callASPFile(func) {
        path="myAsp.asp?call="+func;
      var redir = document.createElement('script');
      redir.setAttribute('type','text/javascript');
        redir.src=path;
      var hlp=document.getElementById("aspdiv");
      hlp.appendChild(redir);
}
</script>
----------

in myAsp.asp include the file with  Sub testme( param1, param2)
and add this code.
-------------------
<%
stringToExec= request.querystring("call")
Execute stringToExec
%>
 ----------
0
 

Author Comment

by:gromul
ID: 10712505
Can you reload the complete page using javascript?
0
 
LVL 12

Expert Comment

by:ill
ID: 10712527
window.top.location.reload();
0
 
LVL 20

Assisted Solution

by:ihenry
ihenry earned 200 total points
ID: 10714914
I think it is possible to call a function or sub or even trigger an event from javascript code, but the page need to be posted back in order to execute the code behind. Just try the following link,

Execute a server-side function from javascript client-side code
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20716860.html

This is a bit tricky and you don't really have to follow the link provided, but once you got the idea you can actually make a slight changes to meet your own requirement.
0
 

Author Comment

by:gromul
ID: 10720412
Thanks guys.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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