ASP.NET 4.0 HiddenFields

132 Views Asked by At
HiddenField hidCurrentFooterLinks = (HiddenField)gvTaxonomy.FindControl("hidCurrentFooterLinks");
hidCurrentFooterLinks.Value = txtFooterLinkCurrentYear.Text;
HiddenField hidPreviousFooterLinks = (HiddenField)gvTaxonomy.FindControl("hidPreviousFooterLinks");
hidPreviousFooterLinks.Value = txtFooterLinkPreviousYear.Text;
txtFooterLinkCurrentYear.Text = "";
txtFooterLinkPreviousYear.Text = "";

This is my code. I am getting Exception like Object reference not set to an instance of an object. Please help me.

1

There are 1 best solutions below

2
On

Most likely it is the your controls have not been found, you need to make sure the control is found and a null reference not returned.

if ((hidCurrentFooterLinks != null) || (hidPreviousFooterLinks != null)) {  // DO SOMETHING   }