locked
pnotify does not work on usercontrol? RRS feed

  • Question

  • User-909867351 posted

    Hi

    I have ons usercontrol lixocontrol with

    ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="lixocontrol.ascx.cs" Inherits="lixocontrol" %>        
    <div class="container mt-2">
        <ul class="nav nav-tabs">
            <li class=" nav-item"><a class="nav-link active" data-toggle="tab" href="#cliente">Cliente</a></li>
        <li class=" nav-item"><a class="nav-link " data-toggle="tab" href="#home">Produtos</a></li>     
      </ul>
        <div class="tab-content">
            <div id="cliente" class="tab-pane container active">
                <p>Aqui estou</p>
            </div>
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <div id="home" class="tab-pane container">                                
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Button ID="Button2" runat="server" Text="Mensagem" OnClick="mensagem2" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>        
        </div>
    </div>

    and cs:

     protected void mensagem2(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showMessage('Informação','Irá gravar os Valores!');", true);
        }

    the pag with usercontrol is the following:

    ascx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="lixo.aspx.cs" Inherits="lixo" %>
    <%@ Register Src="~/lixocontrol.ascx" TagPrefix="uc1" TagName="lixocontrol" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.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: 300
                 });
             }
    </script>
    </head>
    <body>
        <script src="pnotify/pnotify.custom.min.js" ></script>
        <form id="form1" runat="server">       
            <div>
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="mostra" />
            </div>
            <uc1:lixocontrol runat="server" ID="lixocontrol" />
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
        </form>
    </body>
    </html>

    and cs:

      protected void mostra(object sender, EventArgs e)
        {        
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showMessage('Informação','Irá gravar os Valores!');", true);
        }

    When I click in the button on usercontrol (mensagem2) pnotify does not show the message, but when I click in the button of my page (mostra is fired) and works fine. Any help, please?

    Thursday, February 21, 2019 4:34 PM

All replies

  • User475983607 posted

    Use the ClientScriptManager.

                String csname1 = "PopupScript";
                Type cstype = this.GetType();
    
                // Get a ClientScriptManager reference from the Page class.
                ClientScriptManager cs = Page.ClientScript;
    
                // Check to see if the startup script is already registered.
                if (!cs.IsStartupScriptRegistered(cstype, csname1))
                {
                    StringBuilder cstext1 = new StringBuilder();
                    cstext1.Append("<script type=text/javascript> alert('Hello World!') </");
                    cstext1.Append("script>");
    
                    cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
                }

    Thursday, February 21, 2019 5:51 PM