I'm trying to run a javascript function from the code behind in C#. I looked at many resourses on internet but so far no luck. This does not even work with a very simple sample code that I have:
Code behind:
protected void Button2_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this,GetType(),"a","a();", true);
}
In my aspx file:
<script type="text/javascript">
function a()
{
var i = 0;
}
</script>
When I run this I get :
0x800a1391 - JavaScript runtime error: 'a' is undefined
Note :
Also tried :
- ScriptManager.RegisterStartupScript(this,GetType(),"a","a()", true);
- ScriptManager.RegisterStartupScript(this,GetType(),"a","a", true);
Still getting the same error.
Aucun commentaire:
Enregistrer un commentaire