Alertify.JS和ASP.NET:从代码隐藏调用Javascript

时间:2014-01-02 12:17:34

标签: c# javascript jquery asp.net alertify

我有一个问题。

我现在使用当前版本的Alertify.js here。我想将它与我的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>

谢谢。

菊瓒

0 个答案:

没有答案