由于ModalPopupExtender和ASP:LinkBut​​ton On_Command事件不起作用

时间:2018-08-04 13:55:59

标签: c# asp.net .net ajax asp.net-ajax

我正在创建数据管理表单,并为模式弹出面板附加了ajaxcontroltoolkit。从LinkBut​​ton的OnCommend和OnClick在网络中添加modelpopupextender和asp:panel后无法正常工作。 这是我的Web表单的完整代码:-

> <%@ Page Title="Manage Job Title" Language="C#"
> MasterPageFile="~/Portal.Master" AutoEventWireup="true"
> CodeBehind="LInkedin-Manage-JobTitle.aspx.cs"
> Inherits="Forms.LInkedin_Manage_JobTitle" %>
> 
> <%@ Register Assembly="AjaxControlToolkit"
> Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <asp:Content
> ID="Content1" ContentPlaceHolderID="head" runat="server">
> </asp:Content> <asp:Content ID="Content2"
> ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
>     <style>
>         .modalBackground {
>             height: 100%;
>             background-color: #EBEBEB;
>             filter: alpha(opacity=70);
>             opacity: 0.7;
>         }
>     </style>
> 
>     <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
>     <!-- ModalPopupExtender -->
> 
>     <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1"
> CancelControlID="Button4"
> BackgroundCssClass="modalBackground"></cc1:ModalPopupExtender>
>     <asp:Panel ID="Panl1" runat="server" CssClass="Popup" align="center" Style="display: none">
>         <div class="col-lg-12">
>             <div class="panel panel-primary">
>                 <div class="panel-heading">
>                     Add Job Title
>                 </div>
>                 <div class="panel-body">
>                     <div class="row">
>                         <div class="col-lg-12">
>                             <asp:TextBox MaxLength="20" ID="txtjobtitle" runat="server" CssClass="form-control"
> placeholder="Enter Job Title"></asp:TextBox>
>                             <asp:RequiredFieldValidator ControlToValidate="txtjobtitle" ID="RequiredFieldValidator1"
> runat="server" Text="* Job Title Must be Required"
> ForeColor="Red"></asp:RequiredFieldValidator>
>                         </div>
>                     </div>
>                     <div class="row">
>                         <div class="col-lg-6">
>                             <asp:Button ID="AddJobtitle" runat="server" Text="Insert" CssClass="btn btn-primary"
> OnClick="AddJobtitle_Click" />
>                         </div>
>                         <div class="col-lg-6">
>                             <asp:Button ID="Button4" runat="server" Text="Cancel" CssClass="btn btn-primary" />
>                         </div>
>                     </div>
>                 </div>
>             </div>
>         </div>
>     </asp:Panel>
> 
>     <div class="container" style="margin-top: 50px;">
>         <div class="col-lg-12">
>             <div class="row">
>                 <div class="col-lg-10">
>                     <span style="font-size: 20px">Managed Job Titles</span>
>                 </div>
>                 <div class="col-lg-2">
>                     <asp:Button ID="Button1" runat="server" Text="Add Job Title" CssClass="btn btn-primary  " Style="margin-bottom: 10px;"
> />
>                 </div>
>             </div>
>             <hr />
>             <div class="row">
>                 <div class="col-lg-12">
>                     <asp:GridView ID="GridView1" runat="server" CssClass="table table-hover table-striped"
> AutoGenerateColumns="false">
>                         <Columns>
>                             <asp:BoundField DataField="id" HeaderText="ID" />
>                             <asp:BoundField DataField="title" HeaderText="Job Title" />
>                             <asp:BoundField DataField="addedDt" HeaderText="Added Date" />
>                             <asp:TemplateField HeaderText="Action" HeaderStyle-Width="50" ItemStyle-Width="50">
>                                 <ItemTemplate>
>                                     <asp:LinkButton ID="LinkButton1" runat="server" CssClass="fa fa-remove" ToolTip="Delete Job Title"
> CommandArgument='<%# Eval("id") %>'
> OnCommand="LinkButton1_Command"></asp:LinkButton>
>                                     <asp:LinkButton ID="LinkButton2" runat="server" CssClass="fa fa-edit" ToolTip="Edit Details"
> CommandArgument='<%# Eval("id") %>'
> OnCommand="LinkButton2_Command"></asp:LinkButton>
>                                 </ItemTemplate>
>                             </asp:TemplateField>
>                         </Columns>
>                     </asp:GridView>
>                     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
>                 </div>
>             </div>
> 
>         </div>
>     </div> </asp:Content>

这是此页面的查看代码:-

public partial class LInkedin_Manage_JobTitle : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DevSocialListening"].ConnectionString);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
        private void Bind()
        {
            SqlDataAdapter da = new SqlDataAdapter("select * from jobTitle", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }


        protected void AddJobtitle_Click(object sender, EventArgs e)
        {
            DataAcsess d = new DataAcsess();
            d.AddNewJobTitle(txtjobtitle.Text);
            Response.Write("<script>alert('Saved')</script>");
            Bind();

            txtjobtitle.Text = string.Empty;
        }

        protected void LinkButton1_Command(object sender, CommandEventArgs e)
        {

        }

        protected void LinkButton2_Command(object sender, CommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);
        }

请给我关于这个问题的建议。

1 个答案:

答案 0 :(得分:0)

您在Panel控件中具有RequiredField验证器,并且单击按钮和链接命令由于验证失败而未触发。

要解决此问题,请在所需的字段validatior中添加“ ValidationGroup”属性,并在面板内的“保存”按钮上添加相同的验证组属性。这会将所需的字段验证限制为仅在面板内单击“保存”按钮。