Here is my code:
public partial class Image : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e)
{
HtmlMeta tag = new HtmlMeta();
tag.Attributes.Add("property", "og:type");
Header.Controls.Add(tag);
}
}
This is my error:
Server Error in ‘/Kidzania’ Application. 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.Source Error:
Line 18: HtmlMeta tag = new HtmlMeta();
Line 19: tag.Attributes.Add("property", "og:type");
Line 20: Header.Controls.Add(tag);
Source File: d:\Kidzania\Image.aspx.cs Line: 20
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.] Image.Page_Load(Object sender, EventArgs e) in
d:\Kidzania\Image.aspx.cs:20
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+627
i am refer all stackoverflow answer but not solve that problem please any help to assisted me please. thanks in advance for your answers
This how I think it will work.
Also you need to make sure that in your mark up header tag has runat server.