Reputation: 141
I am having a cs file where I want to call the function of js file.
Js File
Function foo(date){
//code
}
In a cs file, I want to call the foo function. Is it possible ? If yes, then how ?
If I want to insert just one alert then this is how I do it, but If I want to call a function, then I dont know the way.
To call just an inline javascript this works
Page.ClientScript.RegisterStartupScript(GetType(), "", "<script type='Text/JavaScript'> alert('Hello');</script>");
Upvotes: 0
Views: 3324
Reputation: 1183
Try putting the function name rather than the whole script itself.
Page.ClientScript.RegisterStartupScript(GetType(),"","foo()",true);
or with ScriptManager:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(),"","foo()",true);
Edit:
Add the boolean value at the end to true
, so it will automatically add script tags, then you dont need to.
Upvotes: 3