通过按钮单击创建模态对话框

时间:2013-01-23 21:35:32

标签: c# asp.net exception-handling updatepanel

我想在更新面板中有一个按钮在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;
    }
}

标记(这是在gridview内部):

<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."};

0 个答案:

没有答案