Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to retrieve values from javascript function to server asp.net for ie

javascript function

XML
<script type="text/javascript">
    function action() {
        var x = 34.4534534;
        var y = -12.3345335;
        var z = x.toString() + ',' + y.toString();
        alert(z);

    }

</script>



serverside function


ScriptManager.RegisterStartupScript(this, Page.GetType(), "anykey", "action()", true);

i was trying like this in order to call client side function so i can get the values . but i am unable to do it .
how to retrieve the values of the action method to a server function .


thanks in advance
Posted
Comments
ZurdoDev 28-Feb-12 8:52am    
What you did is call the JS from the server side. I think what you are asking for is the opposite. How do you get JS to pass to the server side? Use jQuery.ajax() to call your webservice. Server side code executes and then the whole packet is sent to the client and then JS executes so there is no way for the server to wait for JS to execute. http://api.jquery.com/jQuery.ajax/

1 solution

Store the result in a hidden field in the JavaScript function and access the hidden field from the server (after a postback).
 
Share this answer
 
Comments
mohanrajkiller 29-Feb-12 8:46am    
your suggestion are nearing my answer but at first postback the default value of hidden field is returned istead of stored data from client side

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