Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one javascript function which call the code behind method. I am calling that javascript function from code behind on page load function. When I call the javascipt function on page load, its not calling the code behind method. But when I call javscript function with 1 or 2secs delay, it will call code behind method. Is there any ways to solve the above issue.
From code behind: ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "test", "clk0();", true);
From Javascript:
C#
function clk0() {
             var Btninfo0 = document.getElementById('btnreassign');
             Btninfo0.click();
         }

javascript function suppose to call btn_click function in code behind
Posted
Comments
Prasad Khandekar 5-Apr-13 6:07am    
You can not call client side code just like that from server side. Code Behind code executes on the server side, where as Javascript will run in the client browser.
sri senthil kumar 5-Apr-13 7:06am    
you can try __dopostback from javascript

1 solution

You can call the javascript function from code behind file using ClientScript.RegisterStartupScript() method which accepts three parameters.

Example:

JavaScript
function Validate(msg)
{
   alert(msg);
}



Calling The function from code behind file.

C#
protected void Button1_Click(object sender,EventArgs e)
{
   ClientScript.RegisterStartupScript(this.GetType(),"AnyName","javascript: validate('Hello')",true);
}


You can refer the following link about the method ClientScript.RegisterStartupScript().
http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx[^]
 
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