Inject Javascript from asp.net code behind files

后端 未结 4 1338
盖世英雄少女心
盖世英雄少女心 2020-12-08 15:32

Am I injecting this correctly?

string myScriptName = \"EventScriptBlock\";
string myScript = string.Empty;

//Verify script isn\'t already registered
if (!Cl         


        
4条回答
  •  悲哀的现实
    2020-12-08 16:28

    Both RegisterStartupScript and RegisterClientScriptBlock will work.

    Problem lies in myScript (string variable).In myScript variable you need to use alert variable only, as whenever you use this, script tag will be added automatically to your page's HTML at runtime. To check this right on your page and see the source of the page.

    protected void Page_Load(object sender, EventArgs e)
    {
            string myScript = string.Empty;
    
            //myScript = "\n
    
                                     
                  
提交回复
热议问题