开发者

Alert not working what's wrong in this

I write the following to alert but it is not displaying the alert box what's wrong开发者_运维问答 in this

protected void Timer1_Tick(object sender, EventArgs e)
{
    string str = string.Empty;
    str = "Total Count: '" + click + "'";

    Response.Write("<Script>alert('" + str + "')</script>");
    click = 0;
}


You should escape your apostrophes in the following line:

Change:

str = "Total Count: '" + click + "'";

To:

str = "Total Count: \'" + click + "\'";


You have nested single quotes, try without:

    str = "Total Count: " + click;
    Response.Write("<Script>alert('" + str + "')</script>");


You have forgotten the '@' and the ';' characters in the alert function:

Replace this line:

Response.Write("<Script>alert('" + str + "')</script>");

with this:

Response.Write(@"<script type='text/javascript'>alert('" + str + "');</script>");


As the signature of your method is Timer1_Tick, I assume you are using ScriptManager. The correct way to inject javascript with ScriptManager is:

ScriptManager.RegisterClientScriptBlock(this, typeof(this), "alert", "alert('" + str + "');", true)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜