I have a formview with textboxes, a radio button list, and an edit button arranged in the following order:
<asp:textbox id="tb1" runat="server" text='<%# Bind("DATE_1", "{0:d}") %>' />
<asp:calendarextender id="tb1_CalendarExtender" runat="server" targetcontrolid="tb1" />
<asp:textbox id="tb2" runat="server" text='<%# Bind("DATE_2", "{0:d}") %>' />
<asp:calendarextender id="tb2_CalendarExtender" runat="server" targetcontrolid="tb2" />
<asp:button id="EditButton" runat="server" causesvalidation="False" commandname="Edit" text="Edit" enabled='<%# CanEdit(Eval("DATE_1"), Eval("DATE_2")) %>' OnClick="EditButton_Click" />
<asp:radiobuttonlist id="rbl1" runat="server" repeatdirection="Horizontal" text='<%# Bind("DIAG_LL_APPROVAL") %>'>
<asp:ListItem>Approved</asp:ListItem>
<asp:ListItem>Rejected</asp:ListItem>
<asp:ListItem Selected="True">None</asp:ListItem>
</asp:radiobuttonlist>
<asp:textbox id="tb3" runat="server" text='<%# Bind("COMMENTS") %>' maxlength="1000"/>
If tb1
or tb2
is empty (i.e., null) when the edit button is clicked, I need to hide or disable rbl1
and tb3
.
protected void EditButton_Click(object sender, EventArgs e)
{
TextBox t1 = FormViewName.FindControl("tb1") as TextBox;
TextBox t2 = FormViewName.FindControl("tb2") as TextBox;
RadioButtonList rbl = FormViewName.FindControl("rbl1") as RadioButtonList;
TextBox t3 = FormViewName.FindControl("tb3") as TextBox;
if (!string.IsNullOrEmpty(t1.Text) && !string.IsNullOrEmpty(t2.Text))
{
FormViewName.FindControl("rbl1").Visible = true;
FormViewName.FindControl("tb3").Visible = true;
}
else
{
FormViewName.FindControl("rbl1").Visible = false;
FormViewName.FindControl("tb3").Visible = false;
}
}
Error: Object reference not set to an instance of an object