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