简体   繁体   中英

website gridview not working at iis on azure

Good day everyone, I've a problem with the published web app when posting it at azure

so, my code is like 2 pages, one for the datalist, the other one is for input page

the problematic page is containing a gridview with a templatefield that contains 2 image buttons

one is for display block another div and fills the grid within

the other one is for redirect to input page with some session update for flagging the transaction is either new or editing

the problem is, my gridview_rowcommand method is working locally either on quick debugging (IIS Express) or run it via IIS

but when I publish it at azure, the rowcommand not functioning at all

below are some codes

<div class="divWrapperGrid" style="border-top:none;">
                        <div class="divContentGrid" style="min-height:190px;">                
                            <asp:Button ID="btnChange" runat="server" Text="Button" Style="display:none;" OnClick="btnChange_Click"/>
                            <asp:UpdatePanel runat="server" ID="upWHOrder">
                                <ContentTemplate>
                                    <asp:GridView ID="dgWHOrder" runat="server" AutoGenerateColumns="false" AllowPaging="true" ShowHeaderWhenEmpty="true"
                                                    CssClass="data-grid" HeaderStyle-CssClass="data-grid-header" RowStyle-CssClass="data-grid-row" EmptyDataRowStyle-CssClass="data-grid"
                                                    GridLines="None"  EmptyDataText="There is no data"
                                                    OnRowDataBound ="dgWHOrder_RowDataBound" OnRowCommand="dgWHOrder_RowCommand">
                                        <EmptyDataTemplate>
                                            <asp:Label ID="Label2" CssClass="no-data-grid" runat="server">No records found!</asp:Label>
                                        </EmptyDataTemplate>
                                        <Columns>
                                            <asp:TemplateField HeaderStyle-CssClass="hidden-column" ItemStyle-CssClass="hidden-column">
                                                <EditItemTemplate>
                                                    <asp:Label ID="laID" runat="server" Text='<%#Eval("ID")%>'></asp:Label>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="laID" runat="server" Text='<%#Eval("ID")%>'></asp:Label>
                                                </ItemTemplate>                                
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="WarehouseOrderNo" />
                                            <asp:BoundField DataField="OrderDateStr" />
                                            <asp:BoundField DataField="TotalItem" />
                                            <asp:BoundField DataField="Responsible" />                             
                                            <asp:BoundField DataField="MerchantCode" />
                                            <asp:TemplateField ItemStyle-Width="35%" ItemStyle-HorizontalAlign="Right">
                                                <EditItemTemplate>
                                                    <asp:ImageButton ID="btnSave" runat="server" CommandName="save" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/save-icon.png" Width="20px" Height="20px" ToolTip="Save" OnClientClick="return true;" /> 
                                                    <asp:ImageButton ID="btnCancel" runat="server" CommandName="cancel" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/cancel-icon.png" Width="20px" Height="20px" ToolTip="Cancel" OnClientClick="return true;" />
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="btnEdit" runat="server" CommandName="edit" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/edit-icon.png" Width="20px" Height="20px" ToolTip="Update" OnClientClick="return true;" /> 
                                                    <asp:ImageButton ID="btnView" runat="server" CommandName="view" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/delete-xxl.png" Width="20px" Height="20px" ToolTip="View" OnClientClick="return true;" />
                                                </ItemTemplate>
                                            </asp:TemplateField>   
                                        </Columns>
                                    </asp:GridView>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </div>
                    </div>

btnEdit is the redirect processing one btnView is for the view processing one

and the gridview_rowcommand method

protected void dgWHOrder_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int rowIndex = 0;
            rowIndex = Convert.ToInt32(e.CommandArgument);

            string script = string.Empty;
            int HeaderID = 0;

            if (rowIndex > -1)
            {
                GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
                HeaderID = Convert.ToInt32(((Label)row.FindControl("laID")).Text);
            }

            BPWarehouseOrder objBP = new BPWarehouseOrder();
            BOSearch objSrc = new BOSearch();

            switch (e.CommandName)
            {
                case "edit":
                    IsEdit = true;
                    EditItemHeader = (from a in ListHeader
                                      where a.ID == HeaderID
                                      select a).Single();
                    Response.Redirect("WarehouseOrderIns.aspx");
                    break;
                case "view":
                    List<BOWarehouseOrderDatail> objDt = new List<BOWarehouseOrderDatail>();
                    objBP = new BPWarehouseOrder();

                    objSrc = new BOSearch();
                    objSrc.FieldName = "IDWarehouseOrder";
                    objSrc.FieldValue = HeaderID.ToString();
                    objSrc.SearchType = "Equal";

                    objDt = objBP.GetDetailList(objSrc);
                    if (objBP.MsgCode != 0)
                    {
                        script += " alert('" + objBP.MsgDesc + @"');
                                  ";

                        ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), script, true);
                        return;
                    }

                    dgOrderDetail.DataSource = objDt;
                    if (objDt.Count > 0)
                    {
                        dgOrderDetail.PageSize = objDt.Count;
                    }
                    dgOrderDetail.DataBind();

                    script += @" document.getElementById('popup').style.display = 'block';
                               ";
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), script, true);
                    break;
            }
        }

TLDR: publishing website at azure, gridview_rowcommand function not working at azure, but working at local

Regards

Mediocre Programmer

I create the following sample using ASP.NET GridView control inside a UpdatePanel control, it works fine on my Azure web app service, OnRowCommand of the GridView control can be executed as expected.

GridView inside UpdatePanel

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:GridView ID="my_testgrid" runat="server" AutoGenerateColumns="false" OnRowCommand="my_testgrid_RowCommand">
                    <Columns>
                        <asp:TemplateField HeaderText="ID">
                            <ItemTemplate>
                                <asp:Label runat="server" Text='<%#Eval("ID")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Name">
                            <ItemTemplate>
                                <asp:Label runat="server" Text='<%#Eval("Name")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:Button ID="Button1" runat="server" Text="select" CommandName="select" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</form>

Specify data source in Page_Load event

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        dt.Columns.Add("Name");

        dt.Rows.Add("u001", "jack");
        dt.Rows.Add("u002", "fred");

        my_testgrid.DataSource = dt;
        my_testgrid.DataBind();
    }
}

OnRowCommand event

protected void my_testgrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "select")
    {
        string arg = e.CommandArgument.ToString();
    }
}

Browse the web app

在此处输入图片说明

OnRowCommand event can be executed if click [select] button

在此处输入图片说明

To troubleshot the issue, you can try to remote debug your web app and check if something wrong with your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM