I tried to find the ID of the HtmlAnchor web control through FindControl. But the error seems to say that HtmlAnchor web control instance is null.
The error message:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code.
Exception Details:
System.NullReferenceException: Object reference not set to an instance of an
object.
<a id="hypTest" runat="server" href="#"><img src="/_layouts/15/images/picture.PNG" alt="" /></a>
protected void Page_Load(object sender, EventArgs e)
{
HtmlAnchor aURL = new HtmlAnchor();
aURL = (HtmlAnchor)this.Page.FindControl("hypTest");
aURL.HRef = ''http://www.example.com/'';
}
How to fix the problem?