0

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.

Emmanuel F
  • 1,125
  • 1
  • 15
  • 34
  • Huh. I think you should show your code. There must be something specific to the parameters getting passed in. – IAmGroot Jan 17 '12 at 16:33
  • does your page contain updatepanel better show us Markup and also what that linkbutton do – Devjosh Jan 17 '12 at 16:35
  • 1
    Perhaps there's an exception being thrown when you generate your GridView after your link postback? Have you checked for errors with try/catch? – Brissles Jan 17 '12 at 16:36
  • Added code as requested. @Brissles; I wondered the same thing; perhaps the DB query was wrong and returning junk data. I redirected the Dev code to the prod/live DB to see if it was returning junk, but everything seemed fine. – Emmanuel F Jan 17 '12 at 17:04
  • Does Firebug offer any clues? Are there any styles being inadvertently applied to the gridview that are hiding it? – Jagd Jan 17 '12 at 17:11
  • It's not something as basic as having ViewState turned off on the production server is it? You haven't actually show the code that populates the gridview yet. We need to see the page cycle. – mattmanser Jan 17 '12 at 17:13
  • Are you 100% sure that your GridView isn't being rebound to an empty dataset on postbacks? – Jagd Jan 17 '12 at 17:16
  • You say 'and on Page_Load, but only if the user was redirected to the current page with a search as the QueryString' - does this actually occur when the user clicks on your programatically generated link? If so, could this be a QueryString issue that's not qualifying the grid to be rebound? – Brissles Jan 17 '12 at 17:21
  • @mattmanser; As far as I know, `ViewState` is turned on. There isn't any other code that populates the GridView other than `gvExistingPatientsSearch_RowDataBound` and that's only for the `DiseaseState` links. Everything else is bound to the DataSource using `'<%# Bind("Site")%>'` for example. The rest of the page cycle besides what I've written up there I will add to the update, but it's not that much, a few `Session` parameters are set, and the page is redirected. – Emmanuel F Jan 17 '12 at 18:05
  • @Jagd; I'm 100% sure that the GridView is not rebound to an empty dataset and/or set to null. But just to be safe, I am going to put a JS `alert` in all the places it gets reset. – Emmanuel F Jan 17 '12 at 18:09
  • Well, I figured it out. Check out my answer below, it's actually kind of silly and I'm embarrassed that's what it was. Oh well, live and learn. – Emmanuel F Jan 17 '12 at 20:20

1 Answers1

1

Figured out the issue. It's a difference between a secure website and one that's not, really the difference was *http***s** and http, yes the s is what was causing the problem. The reason being is that I rebind the DataSource on OnInit so that when the link is clicked the event gets created and fired. This was a solution someone suggested on a question I asked some time ago.

What I was doing was this:

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();
    }
}

it was the if (Page.Request.UrlReferrer != Page.Request.Url) statement that was causing a problem since the UrlReferrer had https and the Url did not. I've switched the if statement to if(Page.Request.UrlReferrer.LocalPath != Page.Request.Url.LocalPath) instead. It seems to work after testing it.

Hopefully this is the final solution and I won't have anymore issues. Suggestions and comments are greatly appreciated.

Community
  • 1
  • 1
Emmanuel F
  • 1,125
  • 1
  • 15
  • 34