开发者

How to call javascript in for loop code behind?

开发者 https://www.devze.com 2023-04-02 05:03 出处:网络
protected void Button1_Click(object sender, EventArgs e) { for (int i = 0; i < 100; i++) { Page.ClientScript.RegisterClientScriptBlock(GetTyp开发者_如何转开发e(), \"myScript\", \"<script>aler
protected void Button1_Click(object sender, EventArgs e)
{
    for (int i = 0; i < 100; i++)
    {
        Page.ClientScript.RegisterClientScriptBlock(GetTyp开发者_如何转开发e(), "myScript", "<script>alert('hello world');</script>");
    }
}

The alert only execute once, is that possible to execute the alert everytime in the iteration?


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号