Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello ,
how to call a java script function in c # page
i have a function of javascript
XML
<script type="text/javascript">
        function go(loc) {
            document.getElementById('ifm').src = loc;
        }
    </script>

i want to call this function in my c# page button click event and set parameter loc dynamically
how can i do this

Thanks & Regards
Srishti
Posted
Updated 12-May-13 22:59pm
v3

Something like this:
protected void Page_Load(object sender, EventArgs e)      
{
          System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof
           (Page), "script", "go(<yourparameter>)", true);
}

For more detailed description look here[^]
 
Share this answer
 
v2
You can't call JS from the C# since the C# code runs on the server side, until the HTML is prepared by the server to go to the client side.

Inside the HTML that goes to the client side there are your Javascript functions.
What you CAN do is set code to execute on the onClick event of the button on the HTML and thus execute code on the client side before the page does a postBack to the server.

Hers's an example of using the onclick event of a button in Javascript:
JavaScript
<button onclick="myFunction()">Click me</button>


Cheers,
Edo
 
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