我有一箇中繼器,它列出的數據包括我傳遞給用戶控件的ID,直到單擊鏈接按鈕時才顯示。但是,當我點擊鏈接按鈕時,ID已經丟失。將參數傳遞給中繼器內的用戶控件
任何人有任何想法我要去哪裏錯了?
下面是中繼器的代碼:
<asp:Repeater ID="uxPolicyList" runat="server" onitemdatabound="uxPolicyList_ItemDataBound">
<ItemTemplate>
<tr>
<td class="smaller-ctrl">
<img src="Assets/Images/home-icon.gif" alt="Home Insurance Policy" /><%#Eval("PolicyNumber")%>
</td>
<td>
<%#Eval("StartDate","{0:d}")%>
</td>
<td class="center-cell-ctrl">
<%#Eval("Renewal", "{0:d}")%>
</td>
<td class="center-cell-ctrl">
Postcode:<br />
<%#Eval("Postcode")%>
</td>
<td id='<%#Eval("PolicyNumber")%>' class="button-cell">
<asp:LinkButton ID="uxPolicySummaryButton" CssClass="policy-link-ctrl" CommandName="PolicyNumber" CommandArgument='<%#Eval("PolicyNumber")%>' OnCommand="uxPolicySummaryButton_Command" runat="server">Policy summary<br /></asp:LinkButton>
</td>
</tr>
<uc1:PolicySummary ID="uxPolicySummary" PolicyNumber='<%#Eval("PolicyNumber")%>' runat="server" Visible="false" />
</ItemTemplate>
我有這些獲得用戶控件/ set訪問代碼隱藏,但他們總是空白:
public string _policyNumber = string.Empty;
public string PolicyNumber
{
get
{
return _policyNumber;
}
set
{
_policyNumber = value;
}
}
當測試,我在用戶控件中硬編碼了一個值。即
<uc1:PolicySummary ID="uxPolicySummary" PolicyNumber="545545-5454-54545" runat="server" Visible="false" />
...它工作得很好。任何想法表示讚賞
嗨 - 我真的這樣做。我試圖將它設置爲會話變量,但由於頁面生命週期,這似乎發生在控件加載後,因此它不會使用policyNumber加載,因此它爲空白 –
嘗試將其保存到'HiddenField '在你的控制之內檢查我的編輯 –
非常感謝 - 隱藏的字段方法爲我工作。 –