vb.net code works but not c# code - Please help

Hello,

I'm trying to insert the metatags dynamically.
The following vb code works fine:
aspx.vb code:

Protected myTag As System.Web.UI.HtmlControls.HtmlGenericControl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myTag.Attributes("content") = "test"
End Sub

In aspx file head:

<meta id="myTag" runat="server" />

The above code is working great. But the same thing I'm trying to put in C# which is not working.
aspx.cs code:

protected System.Web.UI.HtmlControls.HtmlGenericControl myTag;
private void Page_Load(object sender, System.EventArgs e)
{
myTag.Attributes["content"] = "test";
// Also tried this--- myTag.Attributes("content") = "test";
}

In aspx file head:

<meta id="myTag" runat="server" />

Am I missing any thing? Thank you.
0
ramitippa
11/16/2004 8:08:56 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

2 Replies
1308 Views

Similar Articles

[PageSpeed] 4

The error?
Picky
0
pickyh3d
11/16/2004 11:04:32 PM
No error, but the meta tag is empty when using with C#.
0
ramitippa
11/17/2004 3:51:45 PM
Reply:

Web resources about - vb.net code works but not c# code - Please help - asp.net.getting-started


Students in Los Angeles Back in School After Terror Threat
Schools were closed Tuesday after a threat was emailed to school officials.

2 Arrested in Austria in Connection to Paris Attacks
TIME 2 Arrested in Austria in Connection to Paris Attacks TIME Two people were arrested at a refugee center in Salzburg, Austria in connection ...

Facebook’s Real Name Policy Has Been Relaxed
The world’s largest social network previously mandated that you use your “authentic” name on the service but it will no longer be holding users ...

Kojima Inks PS4 Console Exclusive Deal With Sony, First Post-Konami Game Coming To PC Too
Metal Gear Solid V: The Phantom Pain director Hideo Kojima did not wait long for his contract with Konami to expire before announcing his next ...

Man Who Claimed He 'Fell' and Penetrated Teen Is Cleared of Rape Charges
Remember the English guy from last week who deflected rape charges by saying he had probably fallen inside his 18-year-old victim? Turns out ...

Britain opts out of EU law setting social media age of consent at 16
Facebook, Snapchat and Instagram will be able to process data of anyone 13 and over after agreement reached

Freddie Gray jury deliberates third day in Baltimore
USA TODAY Freddie Gray jury deliberates third day in Baltimore USA TODAY Jurors weighing the fate of the first Baltimore police officer to ...

13 Secret Ways to Invest for the Fed Rate Hike
Eric Dutram and Tracey Ryniec discuss the hidden ways you can cash in on the Fed rate hike using ETFs.

Monster Hunter makes its way into Super Mario Maker
Bring on the event stages and costume rewards, I say! After plowing through all of the new events this week, I'm ready for more. Thankfully, ...

Resources last updated: 12/16/2015 5:02:38 PM