locked
ASP.Net Message Box Alert Display RRS feed

  • Question

  • User838579685 posted

    I am new to ASP.Net and really need to know how can one display an Alert in a webpage. I know that Adobe Flex and the Javascript offer controls to display the Alert but have no idea of this being present in the ASP.Net

    So if anyone can provide the control or a technique to display an alert it would really be helpful

    Thursday, August 20, 2009 10:38 AM

Answers

  • User1696475319 posted

    JavaScript is JavaScript - all these frameworks do is offer you different ways of putting the alert('message'); on the page.  You can either write an alert straight to your page


    <script type="text/JavaScript">
    alert('hello world');

    </script>


    You can use the ASP.NET codebehind to write it to the page

    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);


    You can also response.write it to the page as shown earlier, you can also write the javascript to a literal on the page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 20, 2009 1:11 PM

All replies

  • User-952121411 posted

     Try the code below:

    System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert("Hello this is an Alert")</SCRIPT>")


     

    Thursday, August 20, 2009 11:41 AM
  • User-1839993167 posted

    this might help you

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick = "return confirm('Are you sure you want to delete?');"/>
        


     

     

    Thursday, August 20, 2009 11:46 AM
  • User-1678381114 posted

    In ASp.NET web page to display the alert by using java script as you said alert(); method.

     For more refer the link below how to use alert in ASP.NET

    1) http://weblogs.asp.net/bleroy/archive/2005/12/01/432016.aspx

    2) http://www.beansoftware.com/ASP.NET-Tutorials/Message-Box.aspx

    3) http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=32564

    4) http://aspnet.4guysfromrolla.com/articles/021104-1.aspx

    5) http://www.codeproject.com/KB/webforms/NingLiangSimpleControl.aspx

    6) http://stackoverflow.com/questions/651592/how-to-display-an-error-message-box-in-a-web-application-asp-net-c


    Thursday, August 20, 2009 11:51 AM
  • User1696475319 posted

    JavaScript is JavaScript - all these frameworks do is offer you different ways of putting the alert('message'); on the page.  You can either write an alert straight to your page


    <script type="text/JavaScript">
    alert('hello world');

    </script>


    You can use the ASP.NET codebehind to write it to the page

    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);


    You can also response.write it to the page as shown earlier, you can also write the javascript to a literal on the page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 20, 2009 1:11 PM
  • User-1267218547 posted

     Hi moonlight007,

    From your description, you want to display the messagebox in the page.

    You can use the javascript alert or confirm function for this requirement.

    Of course, you can display a div for message box by the div tag display property.

    By the way, I recommend you use the JQuery plugin for showing the messagebox.

    Facebox
    http://famspam.com/facebox
    http://www.electrictoolbox.com/jquery-facebox-greyed-background/
    http://weblogs.asp.net/kyleholder/archive/2008/01/22/jquery-facebox-and-ajax.aspx

    Thickbox
    http://jquery.com/demo/thickbox/ 

    lightbox
    http://www.balupton.com/sandbox/jquery_lightbox_bal/demo/

    FancyBox
    http://fancy.klade.lv/

    Impromptu
    http://trentrichardson.com/Impromptu/index.php

    Boxy
    http://onehackoranother.com/projects/jquery/boxy/index.php#downloading

    Let me know whether that answers your question, or if I've missed something.

    Tuesday, August 25, 2009 5:25 AM
  • User117089372 posted

    Thanks You..i got proper solutions.to display alert box using server side code


    string myStringVariable = string.Empty;

    myStringVariable = "Welcome";


    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);


    Wednesday, January 6, 2010 11:44 PM
  • User-532524509 posted

    you can also create custom control for alert and conformation see this link.

    http://www.codeproject.com/KB/webforms/NingLiangSimpleControl.aspx 

    Thursday, January 7, 2010 12:46 AM
  • User-2034328377 posted

    Hi,

    There are two scenerios, either you want to display message while staying on clientside or you want to display message from server side i.e. after page postback.

    In any case, alert() of JScript is the only option to display a meassge box. You can invoke any javascript function from code behind as guided in other replies.

    Moreover,  Asp.Net do provide a wide range of Validation Controls to validate web form input. There exists a property ' ShowMessageBox ' in ValidationSummary control, that, if set to true, would display an alert box against a wrong input. To see how to use it, visit Display Message Box Against Wrong Input.

    Another weird approach is to just import System.Windows.Forms namespace and start using MessageBox.Show().

    Don't forget to Mark this as an Answer, if it helps

    Thank you

    Friday, July 9, 2010 7:06 AM
  • User-150497099 posted

    I am new to ASP.Net and really need to know how can one display an Alert in a webpage. I know that Adobe Flex and the Javascript offer controls to display the Alert but have no idea of this being present in the ASP.Net

    So if anyone can provide the control or a technique to display an alert it would really be helpful

    You could try using this method, maybe it can help you

    private void ShowPopUpMsg(string msg)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("alert('");
            sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'"));
            sb.Append("');");
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showalert", sb.ToString(), true);
        }
    Tuesday, August 23, 2011 4:23 AM