0

更新パネル内のボタンにJavaScriptでモーダルダイアログを作成させ、以下のコードをポップアップさせようとしています。私はこれについていくつかの異なる方法を試しましたが、完全に立ち往生しています。

protected void btnRequestPrint_Command(object sender, CommandEventArgs e)
{
    var button = sender as Button;
    var parent = button.Parent;
    var row = parent.DataItemContainer;

    var printLabel = row.FindControl("lblPrints") as Label;
    var literal = parent.FindControl("lJavascriptPrint") as Literal;
    var label = parent.FindControl("lblMessage") as Label;

    switch (e.CommandName)
    {
        case "RequestPrint":
            var productId = Convert.ToInt32(e.CommandArgument);
            currentProduct = productId;
            var customerId = NopContext.Current.User.CustomerId;

            var ei = this.EncryptionService.GetEncryptionInfo(customerId, productId);
            if (ei != null && ei.Prints > 0)
            {
                literal.Text = @"
                        <div id=""removeME"">
                                                    <!-- yes/no dialog -->

                        <div class=""modal"" id=""yesno"">
                            <h2>
                                Did your music print correctly?</h2>
                            <p>
                                &lt;--Printing Instructions for your browser will go here--&gt;</p>
                            <!-- yes/no buttons -->
                            <p>"
                            //<asp:Button runat=""server"" ID=""btnPrintDialogYes"" CssClass=""close btn btn-primary""
                            //    Text=""Yes"" OnClick=""btnPrintDialogYes_Click"" />
                            //<asp:Button runat=""server"" ID=""btnPrintDialogNo"" CssClass=""close btn btn-danger""
                            //    Text=""No"" />
                        +
                        @"
                        <button onclick=""absorbPrint(" + currentProduct + @")"" class=""btn btn-primary close"">Yes</button>
                        <button class=""btn btn-danger close"">No</button>
                        </div>
                        </div>";
           string UtilsScript = @"
                        <script type=""text/javascript"">
                            function absorbPrint(id) {
                                $.ajax({
                                  type: ""POST"",
                                  url: ""checkoutdownload.aspx/absorbPrint"",
                                  data: ""{}"",
                                  contentType: ""application/json; charset=utf-8"",
                                  dataType: ""json"",
                                  success: function(msg) {
                                    console.log(""success"");
                                  }
                                });
                            }

                            var yesnoDialog = $(""#yesno"").dialog({
                                modal: true
                            });
                            $(""#yesno .close"").click(""function() {
                                $(""#yesno"").dialog(""close"");
                            });
                        </script>";
                    var upanel = parent.Parent as UpdatePanel;
                    ScriptManager.RegisterStartupScript(upanel, upanel.GetType(), "PrintSong", UtilsScript, false);

            }
            else
            {
                label.Visible = true;
                label.Text = "No prints available";
                button.Visible = false;
            }
            break;
    }
}

マークアップ (これはグリッドビュー内にあります):

<asp:TemplateField>
        <ItemTemplate>
            <asp:Panel ID="pnlNonFolio" runat="server" Visible='<%# ! IsProductFolio( (int)Eval("ProductId")) %>'>
                <asp:UpdatePanel ID="upnlInstantPrint" runat="server">
                    <ContentTemplate>
                        <asp:Button runat="server" ID="btnRequestPrint" CssClass="btn btn-primary modalInput"
                            Text="Print" CommandName="RequestPrint" CommandArgument='<%# Eval("ProductId") %>'
                            OnCommand="btnRequestPrint_Command" />
                        <asp:Literal ID="lJavascriptPrint" runat="server" />
                    </ContentTemplate>
                </asp:UpdatePanel>
                <asp:Label runat="server" ID="lblMessage" Visible="false" />
            </asp:Panel>
            <asp:Panel ID="pnlFolio" runat="server" Visible='<%#  IsProductFolio( (int)Eval("ProductId")) %>'>
                <asp:Label runat="server" ID="lblIsFolio" Text="This Product Is A Folio" />
            </asp:Panel>
        </ItemTemplate>
    </asp:TemplateField>

必要に応じてさらにコードを貼り付けることができますが、それは単なるプライベート コードであるため、一部を貼り付けることができません。

とにかく、現在これを行っているときに、印刷ボタンをクリックすると次のエラーが発生します。

Uncaught SyntaxError: Unexpected token ILLEGAL
Type.registerNamespace('Sys.WebForms');Sys.WebForms.Res={"PRM_UnknownToken":"Unknown token: \u0027{0}\u0027.","PRM_MissingPanel":"Could not find UpdatePanel with ID \u0027{0}\u0027. If it is being updated dynamically then it must be inside another UpdatePanel.","PRM_ServerError":"An unknown error occurred while processing the request on the server. The status code returned from the server was: {0}","PRM_ParserError":"The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.\r\nDetails: {0}","PRM_TimeoutError":"The server request timed out.","PRM_ParserErrorDetails":"Error parsing near \u0027{0}\u0027.","PRM_CannotRegisterTwice":"The PageRequestManager cannot be initialized more than once."};
4

0 に答える 0