locked
GridView Row Command Event is not firing RRS feed

  • Question

  • User249168428 posted

    Dear all,

    My GridView Row Command Event is not firing when i deploy this application on server, the same code in my local machine works fine,  code is as shown below

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeFile="Urban_Name_Duplicate_WorkOrder.aspx.cs" Inherits="Urban_Name_Duplicate_WorkOrder" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
        <style type="text/css">
            .modal
            {
                ;
                z-index: 999;
                height: 100%;
                width: 100%;
                top: 0;
                background-color: Black;
                filter: alpha(opacity=60);
                opacity: 0.6;
                -moz-opacity: 0.8;
            }
            .center
            {
                z-index: 1000;
                margin: 300px auto;
                padding: 10px;
                width: 130px;
                background-color: White;
                border-radius: 10px;
                filter: alpha(opacity=100);
                opacity: 1;
                -moz-opacity: 1;
            }
            .center img
            {
                height: 128px;
                width: 128px;
            }
        </style>
        <center>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                <ProgressTemplate>
                    <div class="modal">
                        <div class="center">
                            <img src="loader.gif" />
                        </div>
                    </div>
                </ProgressTemplate>
            </asp:UpdateProgress>
        </center>
        <center>
            <div style="text-decoration: underline;">
                <a style="font-size: 20px"><b>Name Duplicate Urban (Workorder)</b> </a>
            </div>
        </center>
        <br />
        <asp:UpdatePanel ID="upd" runat="server" UpdateMode="conditional">
            <Triggers>
                <asp:PostBackTrigger ControlID="Button1" />
            </Triggers>
            <ContentTemplate>
                <center>
                    <table style="border-right: navy 2px solid; border-top: navy 2px solid; border-left: navy 2px solid;
                        border-bottom: navy 2px solid" cellspacing="2" cellpadding="2" width="35%" align="center"
                        border="2">
                        <tr>
                            <td align="right" style="width: 200px;">
                                <asp:Label ID="lblDistrict" runat="server" Text="District : " Font-Bold="True"></asp:Label>
                            </td>
                            <td align="left" style="width: 300px;">
                                <asp:DropDownList ID="ddlDistrict" runat="server">
                                
                                </asp:DropDownList>
                                <asp:Button ID="Button1" runat="server" Text="View" Font-Bold="True" OnClick="Button1_Click" />
                            </td>
                        </tr>
                    </table>
                    <br />
                    <asp:Label ID="lblmsg" runat="server" Font-Bold="True" Font-Size="Medium" Font-Underline="True"
                        ForeColor="Red"></asp:Label>
                    
                    <asp:GridView ID="grdreg" runat="server" AutoGenerateColumns="False" EmptyDataText="NO DATA FOUND"
                        OnRowCommand="grdreg_RowCommand" CellPadding="3" ForeColor="#333333" GridLines="None"
                        Style="border-right: navy 2px solid; border-top: navy 2px solid; border-left: navy 2px solid;
                        border-bottom: navy 2px solid" CellSpacing="3" OnRowEditing="grdreg_RowEditing">
                        <EditRowStyle BackColor="#999999" />
                        <EmptyDataRowStyle Font-Names="Arial Unicode ms" Font-Size="12pt" HorizontalAlign="Center"
                            Font-Bold="True" />
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <Columns>
                            <asp:TemplateField HeaderText="Sl.No">
                                <ItemTemplate>
                                    <%--<%# CType(Container, GridViewRow).RowIndex + 1%>--%>
                                    <%# Container.DataItemIndex + 1 %>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" Font-Names="Arial Unicode ms" Font-Size="10pt" />
                                <ItemStyle HorizontalAlign="Center" Font-Names="Arial" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="District">
                                <ItemTemplate>
                                    <asp:Label ID="lbldname" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DistrictName_Eng") %>'></asp:Label>
                                    <asp:Label Visible="false" ID="lbldcode" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DistrictCode") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle Font-Names="Arial Unicode ms" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Arial" Font-Size="10pt" ForeColor="Black" HorizontalAlign="Left" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Town">
                                <ItemTemplate>
                                    <asp:Label ID="lbltname" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.TownName_Eng") %>'></asp:Label>
                                    <asp:Label Visible="false" ID="lbltcode" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.TownCode") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle Font-Names="Arial Unicode ms" Font-Size="10pt" HorizontalAlign="center" />
                                <ItemStyle Font-Names="Arial" Font-Size="10pt" ForeColor="Black" HorizontalAlign="center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Scheme">
                                <ItemTemplate>
                                    <asp:Label ID="lblsname" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.SchemeName_Eng") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle Font-Names="Arial Unicode ms" Font-Size="10pt" HorizontalAlign="center" />
                                <ItemStyle Font-Names="Arial" Font-Size="10pt" ForeColor="Black" HorizontalAlign="center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="SubScheme">
                                <ItemTemplate>
                                    <asp:Label ID="lblSsname" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.SubSchemeName_Eng") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle Font-Names="Arial Unicode ms" Font-Size="10pt" HorizontalAlign="center" />
                                <ItemStyle Font-Names="Arial" Font-Size="10pt" ForeColor="Black" HorizontalAlign="center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="SeriesYear">
                                <ItemTemplate>
                                    <asp:Label ID="lblsrname" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.SeriesYearName") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle Font-Names="Arial Unicode ms" Font-Size="10pt" HorizontalAlign="center" />
                                <ItemStyle Font-Names="Arial" Font-Size="10pt" ForeColor="Black" HorizontalAlign="center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Benf.Count">
                                <ItemTemplate>
                                    <asp:Label ID="lblbenfcnt" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.BenfCnt") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle Font-Names="Arial Unicode ms" Font-Size="10pt" HorizontalAlign="center" />
                                <ItemStyle Font-Names="Arial" Font-Size="10pt" ForeColor="Black" HorizontalAlign="center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="ApprNo">
                                <ItemTemplate>
                                    <asp:Label ID="lblapprno" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.ApprNo") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle Font-Names="Arial Unicode ms" Font-Size="10pt" HorizontalAlign="center" />
                                <ItemStyle Font-Names="Arial" Font-Size="10pt" ForeColor="Black" HorizontalAlign="center" />
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:Button ID="btnregister" runat="server" Font-Bold="True" CommandName="NameDuplicateUrban"
                                        Text="Click here" ToolTip="Click here to find Name Duplicates" CommandArgument='<%#Eval("DistrictCode")+","+Eval("TownCode")+","+Eval("ApprNo")%>' />
                                </ItemTemplate>
                                <HeaderStyle Font-Names="Arial Unicode ms" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Arial Unicode ms" Font-Size="10pt" HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                        <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle ForeColor="White" HorizontalAlign="Center" BackColor="#284775" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                    </asp:GridView>
                </center>
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Content>
    protected void grdreg_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName == "NameDuplicateUrban")
            {
                string[] arg = e.CommandArgument.ToString().Split(',');
                //string[] arg = e.CommandArgument.ToString().Split(new char[] { ',' });
                int DistrictCode = Convert.ToInt16(arg[0]);
                int TownCode = Convert.ToInt16(arg[1]);
                int ApprNo = Convert.ToInt16(arg[2]);
                NameDuplicateUrban(DistrictCode, TownCode, ApprNo);
                BindData();
                lblmsg.Visible = false;
               
            }
        }

    Somebody please guide me on how to fix this issue.

    Thanks all

    Friday, December 15, 2017 6:42 AM

All replies

  • User1564875471 posted

    I suspect it's related to the UpdatePanel (MS Ajax framework) which might not be installed or not configured correctly on the server. To verify this, please move the gridview outside the update panel and see if it's triggering. If it started to trigger the command, then you need to check MS ajax framework if it's correctly configured in your web.config.

    Which .NET version you are using ?

    Sunday, December 17, 2017 9:13 AM
  • User-1716253493 posted

    Try this

        protected void grdreg_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if(e.Row.RowType==DataControlRowType.DataRow)
            {
                Button button = e.Row.FindControl("btnregister") as Button;
                if (button != null)
                {
                    scriptManager.RegisterAsyncPostBackControl(button);
                }
            }
        }
    Sunday, December 17, 2017 11:52 AM