3

I use below code for call javascript's function from code behind but doesn't call function

//C#
Page.ClientScript.RegisterStartupScript(this.GetType(), "close panel", "CloseFunction()", true);

//javascript
function CloseFunction() {
            alert("call");
            }

3 Answers 3

3

It should be true.

Page.ClientScript.RegisterStartupScript(this.GetType(), "close panel", "CloseFunction()", 
true);

Update Link:

ClientScriptManager.RegisterStartupScript Method

a Boolean value indicating whether to add script tags.

Sign up to request clarification or add additional context in comments.

2 Comments

I use both true and false but doesn't call
It works for me. However, if you call via ajax, you need ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close panel", "CloseFunction()", true);
1

Your last parameter on the C# code should be true, not false. This will add the <script> tag around the script, which will execute it. Otherwise, it just prints the text out to the page.

2 Comments

I use both true and false but doesn't call
Then you have a different problem. Try this in a simple empty page, and you'll see that based on the question you asked, @Win and I have the correct answer.
1

Do not know about other answers, I tried all but didn't worked for me.

If anyone who is not able to do with those than try this :

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "MyJavascriptFunction();", true); 

Ref. this suresh sir Link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.