How to call javascript in for loop code behind?

前端 未结 2 1188
我寻月下人不归
我寻月下人不归 2021-01-07 12:26
protected void Button1_Click(object sender, EventArgs e)
{
    for (int i = 0; i < 100; i++)
    {
        Page.ClientScript.RegisterClientScriptBlock(GetType(),          


        
相关标签:
2条回答
  • 2021-01-07 12:49

    yes by changing it to, note the "myScript" + i, it changes the key om every iteration:

    for (int i = 0; i < 100; i++)
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript" + i, "<script>alert('hello world');</script>");
            }
    
    0 讨论(0)
  • 2021-01-07 12:54

    I have got the solution and for that you have to change key at every loop like:

    Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript", "<script>alert('hello world');</script>");
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript1", "<script>alert('hello world');</script>");
    
    0 讨论(0)
提交回复
热议问题