0

I have a SharePoint Visual WebPart with a Button on it.

WebPart's .ascx

<asp:Button ID="btnGo" CssClass="ms-ButtonHeightWidth" Text="Apply" runat="server" OnClick="BtnAppyClick"/>

On Button Click the event BtnAppyClick gets fired. I also have commented out all the code snippets which i tried.

    protected void BtnAppyClick(object sender, EventArgs e)
    {
        try
        {
            // Page.Response.Write("<script language='JavaScript'>alert('The 60 seconds.')</script>");

            //string script = "<script language='javascript'>alert('The 60 seconds.')</script>";
            //Page.ClientScript.RegisterClientScriptBlock(GetType(), "alert_box", script);

            //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert_box", "alert('The 60 seconds.')", true);

            ClientScriptManager csm = Page.ClientScript;
            csm.RegisterClientScriptBlock(this.GetType(), "alert_box", "<script type=\"text/javascript\" language=\"javascript\">alert('The 60 seconds.');</script>", true);            }
        catch (Exception se)
        {
            lbError.Text = BuildErrorMsg(se);
        }
    }

I simply want to show a Javascript alert box on Button click, but this doesnt work. When i debug my solution the event is getting executed and there is no error.

What is wrong here? And to show, that my code is executing the Button OnClick Event, here is a screenshot which shows that it steps into the event and i could go step by step through the code without any errors:

enter image description here

STORM
  • 4,005
  • 11
  • 49
  • 98

1 Answers1

0
ScriptManager.RegisterClientScriptBlock(this,this.Gettype(),"","alert('wow');",true);
ScriptManager.RegisterStartupScript(this,this.Gettype(),"","alert('wow');",true);
JustLearning
  • 3,164
  • 3
  • 35
  • 52
  • Are you sure your code behind for the button is called at all? – JustLearning Jan 08 '16 at 18:41
  • This helped http://stackoverflow.com/questions/11643578/registerstartupscript-doesnt-work-with-scriptmanager-updatepanel-why-is-that and `ScriptManager.RegisterStartupScript(this,this.Gettype(),"","alert('wow');",true);` is working. – STORM Jan 09 '16 at 10:49