0

我有个问题。

我现在正在使用此处找到的当前版本的 Alertify.js 。我想将它与我的 ASP.NET 应用程序集成。当我从模态对话框中单击“保存”按钮时,它会毫无问题地进入代码隐藏。我试过“警报(“测试”);” 在 ScriptManager.RegisterClientScriptBlock 内部,它会渲染。

现在,当我尝试使用位于我添加的文件之一中的自定义函数时,脚本似乎没有响应,即 Alertify 没有显示。

这是我的自定义 JS 文件中的 JavaScript 代码、我的保存按钮的 C# 代码和 ASP.NET 页面。

JS

function callFeedbackMessage(inputType, inputText) {
    var inputFeedback = inputType;

    e.preventDefault();

    if (inputType == 'Error') {
        alertify.error(inputText);
        return false;
    }
    else if (inputType == 'Success') {
        alertify.success(inputText);
        return false;
    }
    else {
        alertify.log(inputText, "", 10000);
        return false;
    }
}

lnkSave_Click 的 C# 代码

    protected void lnkSave_Click(object sender, EventArgs e)
    {
        Category newCategory = new ProgrammersToolkitLibrary.BOM.Category();
        bool isSuccess = true;

        newCategory.CategoryName = txtCategoryName.Text;
        newCategory.Description = txtDescription.Text;

        isSuccess = CategoryController.CreateNewCategory(newCategory);

        if (isSuccess == true)
        {
            grdCategoriesList.DataBind();
            upCategoriesList.Update();
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", "callFeedbackMessage('Success', 'Okay');", true);
        }
        else
        {
        }
    }

ASP.NET 页面

<%@ Page Title="" Language="C#" MasterPageFile="~/Layout/Layout.Master" AutoEventWireup="true" CodeBehind="Category_List.aspx.cs" Inherits="ProgrammersToolkit.Views.Maintenance.Categories.Category_List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <div style ="text-align:left;">
        <h3>Article Categories</h3>

        <div class="btn-group">
            <button class="btn btn-default" data-toggle="modal" data-target="#AddCategoryModal"><span class="glyphicon glyphicon-plus"></span> Add Category</button>
            <asp:LinkButton ID="LinkButton2" runat="server" CssClass="btn btn-default"><img src="../../../Layout/img/Icon_Excel.gif" /> Export to Excel</asp:LinkButton>
            <asp:LinkButton ID="LinkButton3" runat="server" CssClass="btn btn-default"><img src="../../../Layout/img/Icon_Excel.gif" /> Import from Excel</asp:LinkButton>
        </div>
    </div>

    <br /><br />

    <div class="panel panel-default">

      <div class="panel-heading">
        <div class="row">
            <div class ="col-lg-6">
                <div class="input-group">
                    <asp:TextBox ID="txtSearch" runat="server" CssClass="form-control"></asp:TextBox>

                    <span class="input-group-btn">
                        <asp:LinkButton ID="lnkSearch" runat="server" CssClass="btn btn-default">Search</asp:LinkButton>
                        <asp:LinkButton ID="lnkReset" runat="server" CssClass="btn btn-default">Reset</asp:LinkButton>
                    </span>
                </div>
            </div>
            <div class ="col-lg-6"></div>
        </div>
      </div>
      <div class="panel-body">
          <asp:UpdatePanel ID="upCategoriesList" runat="server" UpdateMode="Conditional">
              <ContentTemplate>
                <asp:GridView ID="grdCategoriesList" runat="server" CssClass = "table table-hover table-responsive" Width="100%" 
                    DataSourceID="odsCategoriesList" AllowPaging="true" PageSize="10" GridLines="None" BorderStyle="NotSet" BorderWidth="0px"
                    AutoGenerateColumns="false">

                    <PagerSettings FirstPageText="<< First" LastPageText="Last >>" NextPageText="Next >"
                                        Position="Bottom" PreviousPageText="< Previous" />

                    <Columns>                 
                        <asp:TemplateField HeaderStyle-CssClass="input-group-addon" ItemStyle-CssClass="input-group-addon">
                            <ItemTemplate>
                                <asp:CheckBox ID="chkSelectItem" runat="server" />
                            </ItemTemplate>
                            <HeaderTemplate>
                                <asp:CheckBox ID="chkSelectAll" runat="server" />
                            </HeaderTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText = "Category Name" ItemStyle-HorizontalAlign="Left">
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkCategoryName" runat="server" OnCommand="lnkCategoryName_Command" 
                                    CommandArgument='<%# Eval("CategoryId") %>' CommandName='<%# Eval("CategoryName") %>' 
                                    Text='<%# Eval("CategoryName") %>'></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="Description" HeaderText="Description" ItemStyle-HorizontalAlign="Left" />
                    </Columns> 

                    <PagerStyle HorizontalAlign="Right" />
                </asp:GridView>
              </ContentTemplate>
          </asp:UpdatePanel>
    
      </div>
  
      <asp:ObjectDataSource ID="odsCategoriesList" runat="server" EnablePaging="True" TypeName="ProgrammersToolkitLibrary.Controller.CategoryController" 
          SelectMethod="GetListOfCategories" SelectCountMethod="GetListOfCategoriesCount"></asp:ObjectDataSource>
    </div>

    <div class="modal fade" id="AddCategoryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">Add New Category</h4>
            </div>
            <div class="modal-body">
                <table style="width:100%;text-align:left;">
                    <tr>
                        <td style = "width: 30%;"><label for="txtCategoryName">Category Name:</label></td>
                        <td>
                            <asp:TextBox ID="txtCategoryName" runat="server" CssClass="form-control"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td style = "width:30%; vertical-align:text-top;"><label for="txtDescription">Description:</label></td>
                        <td>
                            <asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" Rows="3" CssClass="form-control"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
            <asp:LinkButton ID="lnkSave" runat="server" CssClass="btn btn-primary" OnClick="lnkSave_Click" ClientIDMode="Static">Save</asp:LinkButton>
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
        </div>
    </div>

</asp:Content>

谢谢你。

朱灿

4

0 回答 0