Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have 2 asp.net pages I want from code behind of the first page to call a javascript function in the second asp.net page. any examples?
Posted

As far as I know, this is not possible with normal syntax but you can do one thing.
1. Create a separate js file for Javascript code
2. Give reference to that file in both the aspx files
HTML
<script src="yourscript.js"></script>

3. Now you can all the functions contained in the js file

To call Javascript function fro code behind :
C#
Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "YourJSFunction();", true);


Hopefully, it helps :)
 
Share this answer
 
v2
You make first External javascript file. And call this file on page .
like this:
<script type="text/javascript" src="../page/file.js"></script>
Ex.

Code Behind
protected void DoSomethingButton_Click(object sender, EventArgs e)
{ScriptManager.RegisterStartupScript(this, Page.GetType(), "key", "MyFunc()", true);
}
 
Share this answer
 
v2
Comments
Bob712 31-Dec-14 4:44am    
this is not working because in the second page I want to set values of textboxes from parameters passed in the call statement
[no name] 31-Dec-14 5:27am    
If you want to set textboxes in the new page then you should pass the parameters using querystring or session or viewstate. This will help you rather banging your head in some infeasible solutions.
Amresh Bahadur Singh 31-Dec-14 4:53am    
ok, you use parameters function then you make condition in external js file according your parameter.

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