Calling a javascript function from Page_Load in code-behind

后端 未结 8 1222
广开言路
广开言路 2021-01-25 03:49

How can I call a javascript function, that is in the aspx page, from the Page_Load method, in the code-behind?

8条回答
  •  佛祖请我去吃肉
    2021-01-25 04:06

    Why would you want to do this? What's the purpose?

    Anyway you can do the following, but I DON'T recommend it!!! :

         protected void Page_Load(object sender, EventArgs e)
        {
             string pagename = "Test.aspx"; 
             String scriptString = "";            
    
    if(!this.IsStartupScriptRegistered("Startup")) //This is **not** a good practice
    this.RegisterStartupScript("Startup", scriptString); 
        }
    

    Can you supply with more information of what you want to achieve to get better answer..

提交回复
热议问题