Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6911681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:59:18+00:00 2026-05-27T08:59:18+00:00

I have this code to remove an existing meta tag to which i dont

  • 0

I have this code to remove an existing meta tag to which i dont have access because it is in the solution dll it comes with but basically, I want to remove the meta tag content it comes with to our company content. The problem is that it is not finding the meta tag and I think is because of the way I am setting the htmlHead = Page.Header; I think i am missing something there.. but not sure.. This code is in a virtual Page_Load in a Base class.

    HtmlHead pHtml = Page.Header;

    for (int i = pHtml.Controls.Count - 1; i >= 0; i--)
    {
        if (pHtml.Controls[i] is HtmlMeta)
        {
            pMeta thisMetaTag = (HtmlMeta)pHtml.Controls[i];

            if (thisMetaTag.Name == mName)
            {
                pHtml.Controls.RemoveAt(i);
            }
        }
    }

I am not sure if i am giving the correct rederence to the header since this is in a virtual Page_Load in a Base class. Also most of this code was taken from (99%) from here Code for meta tag removal and replacement

Any help would be much appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:59:18+00:00Added an answer on May 27, 2026 at 8:59 am

    It could be an issue with the order the events occur. I created a new page in ASP.NET

     <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="FormMail.WebForm1" %>
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
     <html xmlns="http://www.w3.org/1999/xhtml" >
     <head runat="server">
         <title>Untitled Page</title>
         <meta http-equiv="keyword" name="testy" content="default content" />
     </head>
     <body>
         <form id="form1" runat="server">
         <div>
    
         </div>
         </form>
     </body>
     </html>
    

    I then used:

        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!IsPostBack)
            {
                string mName = "testy";
    
                HtmlHead pHtml = Page.Header;
    
                foreach (HtmlMeta metaTag in pHtml.Controls.OfType<HtmlMeta>())
                {
                    if (metaTag.Name.Equals(mName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        metaTag.Content = "Yeah!";
                        break; //You could keep looping to find other controls with the same name, but I'm exiting the loop
                    }
                }
    
    
                //for (int i = pHtml.Controls.Count - 1; i >= 0; i--)
                //{
                //    if (pHtml.Controls[i] is HtmlMeta)
                //    {
                //        HtmlMeta thisMetaTag = (HtmlMeta)pHtml.Controls[i];
                //        if (thisMetaTag.Name == mName)
                //        {
                //            thisMetaTag.Content = "Yeah!";
                //           // pHtml.Controls.RemoveAt(i);
                //        }
                //    }
                //} 
    
            }
    
        }
    

    When I view the source, I see that the content of the meta tag was modified. Now, you’re issue could be that at the time of looping, the control doesn’t exist (wasn’t added yet) and you’re adding it, and then the built in code is adding it.

    EDIT – Suggesting moving code to PreRender incase controls are added after load but before rendering

        protected override void OnPreRender(EventArgs e)
        {
            if (!IsPostBack)
            {
                string mName = "testy";
    
                HtmlHead pHtml = Page.Header;
    
                foreach (HtmlMeta metaTag in pHtml.Controls.OfType<HtmlMeta>())
                {
                    if (metaTag.Name.Equals(mName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        metaTag.Content = "Yeah!";
                        break;
                    }
                }
            }
            base.OnPreRender(e);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: myVariable which I want to change into trace(myVariable: + myVariable);
So I have this code that takes care of command acknowledgment from remote computers,
I have this code, showmessage('C:\TEMP\'+openfiles[openfilelist.ItemIndex].ID); if removedir('C:\TEMP\'+openfiles[openfilelist.ItemIndex].ID) then showmessage('Removed') else showmessage('Failed'); The message shows
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code that performs an ajax call and loads the results into
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
I have this code <?php session_start(); if (isset($_GET[cmd])) $cmd = $_GET[cmd]; else die(You should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.