javascript function is called from code behind but it response after the events end code example
Example: how to execute javascript after c# function execute
Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","MyFunction()",true);