admin管理员组

文章数量:1399242

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");
            }

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");
            }
Share Improve this question edited Apr 1, 2013 at 19:56 asked Apr 1, 2013 at 19:45 user1729807user1729807
Add a ment  | 

3 Answers 3

Reset to default 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.

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.

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

本文标签: aspnetCall javascript39s function from code behindStack Overflow