Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

How to find HtmlAnchor ID from the web page in C#? Error message: Object reference not set to an instance of an object.

$
0
0

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?





Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>