I am attempting to set the visibility of the "DeleteButton" in the ItemTemplate of a FormView.
<asp:LinkButton runat="server" Text="Delete" CommandName="Delete" ID="DeleteButton" CausesValidation="False" CssClass="btn btn-sm btn-danger buttonSpace" OnClientClick="return confirm('Are you sure you want to delete this vendor? You will not be able to recover them once deleted.');"/>
Here's what I'm attempting to use:
protected void fvVenDets_DataBound(object sender, EventArgs e)
{
if (fvVenDets.CurrentMode == FormViewMode.ReadOnly)
{
LinkButton lbDelete = fvVenDets.FindControl("DeleteButton") as LinkButton;
lbDelete.Visible = false;
}
else
{
LinkButton lbDelete = fvVenDets.FindControl("DeleteButton") as LinkButton;
lbDelete.Visible = true;
}
}
But when the page loads I get a Null Reference Exception. What am I doing wrong?