當我們的生產服務器上點擊一個鏈接時,我的GridView消失,我有一個真實的不穩定的情況。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個地方,當s earch按鈕被點擊,並在Page_Load
上,但只有當用戶被重定向到當前頁面並且搜索爲QueryString
。
一旦鏈接被點擊,幾Session
變量獲取設置(在CommandArguments
組發現BuildDiseaseStateLinks
的那些和用戶被重定向到另一個網頁。
我該怎麼辦可能會丟失?碼是數據庫是相同的,數據庫是相同的,IIS設置是相同的(除了應用程序池,一個是使用經典(Prod/Live)和其他集成;我切換Prod/Live到Integrated,並沒有做任何事情
建議,意見,任何事情!
Thanks in提前。
[編輯]:根據要求添加了一些代碼。原本並沒有這樣做,因爲我認爲代碼可能不是問題。它適用於一個版本,而不是其他版本。
呵呵。我認爲你應該顯示你的代碼。必須有一些特定的參數傳遞進去。 – Doomsknight 2012-01-17 16:33:32
你的頁面是否包含updatepanel更好地向我們展示標記以及鏈接按鈕的作用 – Devjosh 2012-01-17 16:35:06
也許在鏈接回發之後生成GridView時會拋出異常?你用try/catch檢查錯誤嗎? – Brissles 2012-01-17 16:36:23