Solved

Call ASP.NET sub from javascript

Posted on 2004-03-30
5
595 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now