how to execute a javascript block code using ScriptManager in asp.net?

51 Views Asked by At

Below code is working but when I want to add 2 js commands it doesn't. For example "alert('hello1');alert('hello2');". Does anyone has any solution for this?

StringBuilder sb = new StringBuilder();
sb.Append("alert('hello1');");
ScriptManager.RegisterStartupScript(page, page.GetType(), "mesaj", sb.ToString(), true);
1

There are 1 best solutions below

1
Albert D. Kallal On

Hum, this works for me:

    protected void Button1_Click(object sender, EventArgs e)
    {

        StringBuilder sb = new StringBuilder();
        sb.Append("alert('hello1');alert('hello2');");
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "mesaj", sb.ToString(), true);
    }

And I get/see this

enter image description here