strScriptString = "alert('Hello');";
开发者_运维技巧
ScriptManager.RegisterStartupScript(Page, this.GetType(), "Startup", strScriptString, true);
btn_Click(this, null);
The alert is not showing up :( please help
You need to still put the script tags around your alert:
strScriptString = "<script>alert('Hello');</script>";
EDIT
My mistake, read the wrong RegisterStartupScript class
Have you checked the source of the page for the script using Firebug? I'll hazard a guess that if you remove btn_Click(this, null);
it may work.
You can add following code snippet into page_Load..
btnUpdate.Attributes.Add("onclick", "GetAlert();");
Button Click event in code behind.
protected void btnUpdate_Click(object sender, EventArgs e)
{
btnUpdate.Text = "Reload";
}
Button in aspx page
<asp:Button ID="btnUpdate" runat="server" Text="Submit" OnClick="btnUpdate_Click"/>
Javascript for alert
<script>
function GetAlert() {
alert("123");
return true;
}
</script>
If you're looking to show an alert before the server-side event fires, use OnClientClick
, and return true.
<asp:Button ID="Button1" runat="server" OnClientClick="alert('Hi!');return true;" ... />
精彩评论