How to call javascript function from code?

I want to execute javascript function from code by page.

I have two ways that I can call javascript html pages in my code first.

the second is that I can write a javascript function in my code.

but I'm not the one that is better, and how can I do it.

Please tell me how I can do this.

+1
source share
3 answers
ScriptManager.RegisterStartupScript(...)

Look here for details.

+7
source

Try the following in your code.

ClientScript.RegisterStartupScript(GetType(), "scrptName", "javascript: alert('hi'); ", true);

You can replace alert ('hi'); with your javascript function that you want to call from code.

+1
source

Js- script, .

Page.RegisterStartupScript("key","value")

key - , script . "PageClose" ;

stringBuilder str = new StringBuilder()
str.Append("<script = language='javascript'>");
str.Append("window.close();");
str.Append("</script>")

, window.close, js- , script ,

, script

Page.RegisterStartUp("PageClose",str.ToString());

javascript ,

Page.ClientScriptBlock("PageClose",str.ToString());

JS- ,

,

+1

Source: https://habr.com/ru/post/1764830/


All Articles