Reputation: 4259
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;
}
Upvotes: 0
Views: 1066
Reputation: 11
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>");
Upvotes: 1
Reputation: 153
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)
Upvotes: 0
Reputation: 161012
You have nested single quotes, try without:
str = "Total Count: " + click;
Response.Write("<Script>alert('" + str + "')</script>");
Upvotes: 2
Reputation: 49423
You should escape your apostrophes in the following line:
Change:
str = "Total Count: '" + click + "'";
To:
str = "Total Count: \'" + click + "\'";
Upvotes: 4