locked
Custom Message Alert RRS feed

  • Question

  • User1769015664 posted

    Is there a way to modify the following code to bring up a custom alert without the default title "localhost:12354 says" and the box in color?

    public void ShowMessageBox(Page page, string message)
        {
            Type cstype = page.GetType();
    
            ClientScriptManager cs = page.ClientScript;
    
            int ScriptNumber = 0;
            bool ScriptRegistered = false;
            do
            {
                ScriptNumber++;
                ScriptRegistered = cs.IsStartupScriptRegistered(cstype, "PopupScript" + ScriptNumber);
            } while (ScriptRegistered == true);
    
            cs.RegisterStartupScript(cstype, "PopupScript" + ScriptNumber, "alert('" + message + "');", true);

    Wednesday, August 12, 2020 6:00 PM

All replies

  • User-943250815 posted

    You are using "alert" which is generated by browser itself. So there is no way to change browser behavior.
    But you can use a javascirpt library and make a more elegant alert popup.
    Try https://sweetalert2.github.io/

    Thursday, August 13, 2020 12:13 AM
  • User158811806 posted

    I don't have to use "alert" if you help me with an alternate.  I just want to display a message if a required field value is not entered and a Button is clicked.

    Thursday, August 13, 2020 4:42 AM
  • User-943250815 posted

    To validade fields on webforms use Validator Controls. Check here https://www.codemag.com/Article/0307101/Validating-Data-On-Web-Forms

    Thursday, August 13, 2020 11:41 AM