Passing parameter to user control inside repeater
I have a repeater that lists data including an ID that I pass to a user control that is not visible until I click a linkbutton. However, when I have clicked the linkbutton, the ID has been lost.
Anyone have any idea where I'm going wrong?
Here is the code for the repeater:
<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>
I have these get/set accessors in the user control code-behind, but they're always blank:
public string _policyNumber = string.Empty;
public string PolicyNumber
{
get
{
retu开发者_JAVA技巧rn _policyNumber;
}
set
{
_policyNumber = value;
}
}
When testing, I hard coded a value in the user control. i.e.
<uc1:PolicySummary ID="uxPolicySummary" PolicyNumber="545545-5454-54545" runat="server" Visible="false" />
...and it worked fine. Any ideas appreciated
try to reassign value of PolicyNumber
property inside OnCommand
event with the value of CommandArgument
Edit
or save it into HiddenField
inside your control
public string PolicyNumber
{
get
{
return MyHiddenField.Value;
}
set
{
MyHiddenField.Value = value;
}
}
I think you might be missing the ViewState backing store.
public string PolicyNumber
{
get { return ViewState["policyNumber"] as string; }
set { ViewState["policyNumber"] = value; }
}
精彩评论