I have a real precarious situation where my GridView disappears when a link is clicked on our production server.
It works like this:
- User does a search, GridView gets generated
- On page generation, a link gets generated
- user clicks on the link, and the GridView disappears.
In the past I've experienced issues where only the links would disappear because the links were being generated to late in the page life-cycle. But this time it seems to be different.
What makes this even more bizarre is that this only happens on our production/live server on IIS. If I create a new site under IIS with the exact same compiled code, exact same DB connection strings, etc, the GridView works.
Here is the section that contains the 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>
The code that generates the rows for the GridView is this:
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);
}
}
The following is the method 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);
}
}
}
The gvExistingPatientsSearch
gets bound in 2 places, when the search button is clicked, and on Page_Load
, but only if the user was redirected to the current page with a search as the QueryString
.
Once a link has been clicked, a few Session
variables get set (the ones found on the CommandArguments
set in BuildDiseaseStateLinks
and the user is redirected to another page.
What could I possibly be missing? Code is the same, DB is the same, IIS settings are identical (except for the Application Pools, one is using classic (the Prod/Live) and the other Integrated; I switched Prod/Live to Integrated and that didn't do anything.
Suggestions, comments, anything!
Thanks in advance.
[EDIT]: Added some code as requested. Didn't originally do it since I figured the code may not be the issue. It works in one version and not the other.