locked
Pnotify problem - I have to write something RRS feed

  • Question

  • User-909867351 posted

    Hi 

    Strange behavoir

    My cs page:

    protected void Button1_Click(object sender, EventArgs e)
        {
            //Response.Write("aqui passei");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showMessage('Exemplo prático','Funciona tudo ok');", true);
        }

    my aspx page

     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" ></script>
        <script src="pnotify/pnotify.custom.min.js" ></script>
        <link rel="stylesheet" type="text/css" href="pnotify/pnotify.custom.min.css" />
        <script>      
        function showMessage(title, msg)
        {        
            debugger;
            new PNotify({
                title: title,            
                text: msg,
                type: 'success',
                delay: 500
            });
        }
    </script>

    If I have  Response.Write("aqui passei"); it works otherwhise does not work.

    Why?

    Thank you

    Thursday, February 14, 2019 7:22 PM

Answers

  • User-893317190 posted

    Hi mariolopes,

    Not clear about how Pnotify realizes the message pop up,but when you write response.write , the pnotify script will be moved into body element  instead of the head.

    You could open F12 to check.

    So , if you want  your code to work without Response.Write , you could move your  pnotify  into body instead of head.

    <head runat="server">
        <title></title>
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" ></script>
    
        <link href="pnotify.custom.min.css" rel="stylesheet" />
      
    </head>
    <body>
            <script src="pnotify.custom.min.js"></script>
         <script>      
        function showMessage(title, msg)
        {        
            debugger;
            new PNotify({
                title: title,            
                text: msg,
                type: 'success',
                delay: 500
            });
        }
    </script>
        <form id="form1" runat="server">
            <asp:Button ID="Button1" runat="server" Text="Button"  OnClick="Button1_Click"/>
    
    
        </form>

    There is another way I have tried.That is to use window.onload or $(function())

    protected void Button1_Click(object sender, EventArgs e)
            {
    
    
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", @"
    
    $(function(){
    
    showMessage('title','msg')
    })
    
    ", true);
    
            }

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 15, 2019 1:47 AM