Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to call vb.net function from javascript function
i made this
<script type="text/javascript">
        function test(imgPath) {
            alert(imgPath);
            
            <%deleteImg(imgPath) %>
        };
    </script>


but i had error

VB
Error   1   'imgPath' is not declared. It may be inaccessible due to its protection level.


any help ?
Posted
Comments
[no name] 1-Jul-14 17:43pm    
The error message is pretty self explanatory is it not? Where is "imgPath" declared?
Sergey Alexandrovich Kryukov 1-Jul-14 20:00pm    
There is no such thing as "Java script": Java is not a scripting language. Javascript you are using has nothing to do with Java. (And, actually, nothing to do with VB.NET).
—SA

1 solution

In the Web world, Javascript never ever call server-side methods, as it works under the browser, on client side, and ASP.NET works on the server side only. Client side invokes server-side script only if an HTML request is sent. Therefore, you need to post something. You can do it using Ajax (and one way of doing it is using jQuery .ajax()):
http://en.wikipedia.org/wiki/Ajax_%28programming%29[^],
http://api.jquery.com/jquery.ajax[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900