简体   繁体   English

网站GridView在Azure的IIS上不起作用

[英]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 有问题的页面包含一个带有templatefield的gridview,该templatefield包含2个图像按钮

one is for display block another div and fills the grid within 一个是用于显示块另一个div并填充其中的网格

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 问题是,我的gridview_rowcommand方法在本地快速调试(IIS Express)上运行,或者通过IIS运行

but when I publish it at azure, the rowcommand not functioning at all 但是当我以天蓝色发布它时,rowcommand根本不起作用

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 btnEdit是一种重定向处理,btnView是一种用于视图处理的重定向

and the gridview_rowcommand method 和gridview_rowcommand方法

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 TLDR:在azure上发布网站,gridview_rowcommand函数在azure上不起作用,但在本地

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. 我在UpdatePanel控件内使用ASP.NET GridView控件创建以下示例,该示例在我的Azure Web应用程序服务上运行良好,可以按预期执行GridView控件的OnRowCommand

GridView inside UpdatePanel UpdatePanel内的GridView

<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 在Page_Load事件中指定数据源

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 OnRowCommand事件

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 如果单击[选择]按钮,则可以执行OnRowCommand事件

在此处输入图片说明

To troubleshot the issue, you can try to remote debug your web app and check if something wrong with your code. 要解决此问题,您可以尝试远程调试Web应用程序,并检查代码是否有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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