Gridview在链接点击时消失

时间:2012-01-17 16:30:59

标签: c# asp.net gridview iis-6

当我们的生产服务器上点击链接时,我的GridView消失了,这是一个非常危险的情况。

它的工作原理如下:

  • 用户进行搜索,生成GridView
  • 在页面生成时,会生成一个链接
  • 用户点击链接,GridView消失。

在过去,我遇到过只有链接会消失的问题,因为链接是在页面生命周期的后期生成的。但这次似乎有所不同。

这更令人奇怪的是,这只发生在IIS上的生产/实时服务器上。如果我使用完全相同的编译代码,完全相同的数据库连接字符串等在IIS下创建一个新站点,GridView可以工作。

以下是包含GridView的部分:

<div class="PGE_SearchResult">    
 <asp:Panel ID="pnlWrapper" runat="server" CssClass="addSearchPanelStyle">        
    <asp:GridView ID="gvExistingPatientsSearch" runat="server" AutoGenerateColumns="false" DataKeyNames="PatientId" CssClass="addSearchGridViewStyle"
        AlternatingRowStyle-CssClass="STD_GridView_AlternateRow" RowStyle-CssClass="STD_GridView_Row"
        HeaderStyle-CssClass="gvFixedHeader" FooterStyle-CssClass="STD_GridView_Footer" 
        OnRowDataBound="gvExistingPatientsSearch_RowDataBound">
        <Columns>
            <asp:TemplateField HeaderText="Patient ID" ItemStyle-CssClass="PGS_PSR_PatientID">
                <ItemTemplate>
                   <asp:LinkButton ID="lnkPatientSearch" runat="server" Text='<%# Bind("PatientId")%>' OnClick="OnPatientIDClick" CommandArgument='<%# Eval("PatientId")+ ";" + Eval("PatientStatus")+ ";" + Eval("DOB") + ";" + Eval("DiseaseStates") + ";" + Eval("DiseaseStateIds")%>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="PatientName" HeaderText="Patient Name" ItemStyle-CssClass="PGS_PSR_Site"/>
            <asp:BoundField DataField="DOB" HeaderText="Date of Birth" HtmlEncode="False" ItemStyle-CssClass="PGS_PSR_DOB"/> 
            <asp:TemplateField HeaderText="Site(s)" SortExpression="Site" ItemStyle-CssClass="PGS_PSR_Site">
                <ItemTemplate>
                    <asp:Label ID="lblSiteSearch" runat="server" Text='<%# Bind("Site")%>'></asp:Label>                        
                </ItemTemplate>
            </asp:TemplateField>               
            <asp:BoundField DataField="SiteMRN" HeaderText="Site MRN" HtmlEncode="False" ItemStyle-CssClass="PGS_PSR_DOB"/>
            <asp:TemplateField HeaderText="Disease State(s)" ItemStyle-CssClass="PGS_PSR_Site">
                <ItemTemplate>
                    <asp:Panel ID="diseaseStatePanel" runat="server">
                    </asp:Panel>
            </ItemTemplate>
            </asp:TemplateField>                         
        </Columns>
    </asp:GridView>
</div>

为GridView生成行的代码是:

    protected void gvExistingPatientsSearch_RowDataBound(object sender, GridViewRowEventArgs e)
{
    DataRowView patientData = (DataRowView)e.Row.DataItem;
    string diseaseStates = patientData["DiseaseStates"] as string;
    string diseaseStateIds = patientData["DiseaseStateIDs"] as string;
    int PatientID = (int)patientData["PatientId"];
    int patientStatus = (int)patientData["PatientStatus"];
    DateTime DOB = DateTime.Parse(patientData["DOB"] as string);
    if (e.Row.RowIndex != -1)
    {
        e.Row.Cells[2].Enabled = true;

        LinkButton lnkPatientSearch = (LinkButton)e.Row.FindControl("lnkPatientSearch");
        lnkPatientSearch.Enabled = false;

        Panel diseaseStatePanel = (Panel)e.Row.FindControl("diseaseStatePanel");
        BuildDiseaseStateLinks(diseaseStatePanel, diseaseStates, diseaseStateIds, PatientID, patientStatus, DOB, true);
    }
}

以下是方法BuildDiseaseStatelinks()

private void BuildDiseaseStateLinks(Panel diseaseStatePanel, string diseaseStates, string diseaseStateIDs, int PatientID, int patientStatus, DateTime DOB, bool isAllowed)
{
    string[] diseaseStateIdsSplit = diseaseStateIDs.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

    string[] diseaseStateSplit = diseaseStates.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

    for (int i = 0; i < diseaseStateSplit.Length; i++)
    {
        string diseaseState = diseaseStateSplit[i];
        string diseaseStateID = diseaseStateIdsSplit[i];

        LinkButton diseaseStateLink = new LinkButton();
        diseaseStateLink.Attributes.Add("style", "float:left");
        diseaseStateLink.Text = diseaseState;
        diseaseStateLink.CommandArgument =
            PatientID + "|" + patientStatus + "|" + DOB.ToShortDateString() + "|" + diseaseState + "|" + diseaseStateID;

        if (isAllowed)
        {
            diseaseStateLink.CommandArgument += "|Allowed";
        }
        else
        {
            diseaseStateLink.CommandArgument += "|NotAllowed";
        }

        diseaseStateLink.CommandName = "OnDiseaseStateLinkClick";
        diseaseStateLink.Command += new CommandEventHandler(OnDiseaseStateLinkClick);

        diseaseStatePanel.Controls.Add(diseaseStateLink);

        if (i < diseaseStateSplit.Length - 1)
        {
            Label splitLabel = CreatePipeLabel();
            diseaseStatePanel.Controls.Add(splitLabel);
        }
    }
}

单击搜索按钮时gvExistingPatientsSearch绑定在2个位置,Page_Load上绑定QueryString,但仅当用户被重定向到当前页面并且搜索为{{1}时}。

点击链接后,会设置一些Session个变量(在CommandArgumentsBuildDiseaseStateLinks设置的变量,用户将被重定向到另一个页面。

我可能会错过什么?代码是一样的,DB是相同的,IIS设置是相同的(除了应用程序池,一个是使用经典(Prod / Live)和另一个集成;我将Prod / Live切换到集成并且没有做任何事情。

建议,评论,任何事情!

提前致谢。

[编辑] :根据要求添加了一些代码。最初没有这样做,因为我认为代码可能不是问题。它适用于一个版本而不是另一个版本。

1 个答案:

答案 0 :(得分:1)

找出问题所在。这是安全网站和不安全网站之间的区别,真正的区别是* http *** s **和 http ,是的 s 是造成问题的原因。原因是我在OnInit上重新绑定DataSource,以便在单击链接时创建并触发事件。这是suggested我前一段时间问question的解决方案。

我在做的是:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    // if being redirected from another page, remove the search attributes
    // so it doesn't load the Search Grid view
    if (Page.Request.UrlReferrer != Page.Request.Url)
    {
        Session[UNMGeneralConstants.SearchAttributes] = null;
    }

    UserManagementBO userManagementBO = new UserManagementBO();
    dsUserInSites = userManagementBO.GetSitesNameForUser(new Guid(Session[SessionVariables.Ses_UserId].ToString()));

    DataSet dsSearchResults2 = Session[UNMGeneralConstants.SearchAttributes] as DataSet;
    if (dsSearchResults2 != null && dsSearchResults2.Tables.Count != 0)
    {
        gvExistingPatientsSearch.DataSource = dsSearchResults2;
        gvExistingPatientsSearch.DataBind();
    }
    else
    {
        gvExistingPatientsSearch.DataSource = null;
        gvExistingPatientsSearch.DataBind();
    }
}
由于UrlReferrer有if (Page.Request.UrlReferrer != Page.Request.Url)且Url没有,因此导致问题的是https语句。我已将if语句切换为if(Page.Request.UrlReferrer.LocalPath != Page.Request.Url.LocalPath)。它似乎在测试后工作。

希望这是最终的解决方案,我不会再有问题了。非常感谢您的建议和意见。