I want to enable or disable 'ParticipateBtn' depending on EventStartDate. I am getting this error:Object reference not set to an instance of an object.
Start Date : <%# CheckEnability((DateTime)Eval("Event_Start_Date")) %>
<asp:Button runat="server"
ID="ParticipateBtn"
CommandName="Participate"
CommandArgument='<%# Eval("Event_Id") + "|" + Eval("Event_Name") + "|" + Eval("Volume") + "|" + Eval("Tournament_Id") %>'
Text="Participate" />
</ItemTemplate>
<FooterTemplate></FooterTemplate>
<SeparatorTemplate>
<hr style="color:Silver; height:1px;" />
</SeparatorTemplate>
</asp:Repeater>
The code behind...
//Code behind
protected string CheckEnability(DateTime eventstartdate)
{
if (eventstartdate.Date < DateTime.Now.Date)
{
Button btn = (Button)Repeater1.FindControl("ParticipateBtn");
btn.Enabled = false;
}
return eventstartdate.ToString("yyyy-MM-dd");
}
Controls don't exist in the repeater until it has been databound, and then each control in the ItemTemplate exists once per item - so if you bind to a source with 3 items, there will be 3 ParticipateBtns. You need to know which one you want before you can find it. Once you do, you can get it like so:
myRepeater.Items[1].FindControl("ParticipateBtn");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With