You must Sign In to post a response.
  • Category: ASP.NET

    Messagebox inside button control

    I have fileupload control and separate button control(update)

    I need message box on clicking update button.

    I have tried a simple message box like below:

    string jv = "<script>alert('Hello');</script>";
    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", jv, false);

    But no popup.. Please help me on this
  • #765392
    You can use ClientScript.RegisterStartupScript(this, "alert", jv, true);
    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", jv, true);
    Hope it helps.
    Shashikant Gurav

  • #765394

    Try this code

    string strScript="Saved Data!..";
    ClientScript.RegisterStartupScript(GetType(), "clientScript", strScript);

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765395
    There are many reason behind not working this code, here are some of them
    1. This code now working when the page does not have a server side form e.g.
    < form id="form1" runat="server">... < /form>

    2. When you use RegisterClientScriptBlock the Javascript code is inserted early in the page, so it will run before the elements are loaded.
    Use RegisterStartupScript instead, which places the code at the end of the form.
    I think it should work...

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765402
    Hi Lily,

    Refer below..
    It is like if textbox field is empty, giving message box on click of button control..

    protected void Button1_Click(object sender, EventArgs e)
    if (TextBox1 .Text =="" )
    string sMandatoryFields = "number";
    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Hi", "alert('The Field " + sMandatoryFields + " is mandatory');", true);

    Hope this will help you

    Never lose hope..You never know what tomorrow will bring

  • #765508
    ScriptManager.RegisterClientScriptBlock will work recently in my project I worked with this.

  • #765511
    Hi Lily.

    This will work. Make sure javascript is enabled in browser.

    string jv = "<script>alert('Do you want to update?');</script>";
    ScriptManager.RegisterStartupScript(Page, typeof(Page), "alert", jv, false);

    Else use onclick function for button click, call javascript function which returns true and display the messagebox you want to show.

    Sridhar Thota.
    Editor: DNS Forum.

  • #765542
    Hi Lily,

    if you want to show message after finishing your work from code behind then use this syntax at the end of your button click event last line.

    Hide Copy Code
    protected void btnUpdate_Click(object sender, EventArgs e)
    //other work code here
    //like insert data code goes here
    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "anything", "alert('File Uploaded Sucessfully');", true);

    or just simply want to add javascript mesage from design side then use like this...

    <asp:button id="btn" runat="server" text="Javascript Click" onclientclick="javascript:alert('File Uploaded Sucessfully');" xmlns:asp="#unknown" />

    Hope it helps!

  • #765547
    Hi lily,

    There is no issues in your code, it might be effect with some other part of your code block, request you to kindly check the code in debugger and let me know if you are really struck with the code block which you provide.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • Sign In to post your comments