Solved

Call ASP.NET sub from javascript

Posted on 2004-03-30
5
594 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
Comment Utility
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
Comment Utility
Can you reload the complete page using javascript?
0
 
LVL 12

Expert Comment

by:ill
Comment Utility
window.top.location.reload();
0
 
LVL 20

Assisted Solution

by:ihenry
ihenry earned 200 total points
Comment Utility
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
Comment Utility
Thanks guys.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

17 Experts available now in Live!

Get 1:1 Help Now