开发者

Javascript alert before a event call not firing

开发者 https://www.devze.com 2023-04-12 10:57 出处:网络
strScriptString = \"alert(\'Hello\');\"; 开发者_运维技巧 ScriptManager.RegisterStartupScript(Page, this.GetType(), \"Startup\", strScriptString, true);
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;" ... />
0

精彩评论

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

关注公众号