|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ControlCollection.Remove bugthis code only removes the first HtmlMeta control even though i loop through all of the controls: <%@ Page Language="C#" %> <script runat="server"> void Page_Load(Object Sender, EventArgs E) { foreach (Control ctl in Page.Header.Controls) if (ctl.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlMeta") Page.Header.Controls.Remove(ctl); } </script> <html> <head runat="server"> <title>HtmlMeta Test Page</title> <meta name="description" content="long description" /> <meta name="keywords" content="keyword list" /> </head> <body> Done! </body> </html> thanks for any help with this. Abraham Andres Luna напиÑав:
Show quoteHide quote > hello everyone, "The foreach statement is used to iterate through the collection to get> > this code only removes the first HtmlMeta control even though i loop through > all of the controls: > > <%@ Page Language="C#" %> > <script runat="server"> > void Page_Load(Object Sender, EventArgs E) > { > foreach (Control ctl in Page.Header.Controls) > if (ctl.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlMeta") > Page.Header.Controls.Remove(ctl); > } > </script> > <html> > <head runat="server"> > <title>HtmlMeta Test Page</title> > <meta name="description" content="long description" /> > <meta name="keywords" content="keyword list" /> > </head> > <body> > Done! > </body> > </html> > > thanks for any help with this. the desired information, but should not be used to change the contents of the collection to avoid unpredictable side effects..." (MSDN) for(int i=Page.Header.Controls.Count-1; i>=0; i--) if (Page.Header.Controls[i].GetType().ToString() == "System.Web.UI.HtmlControls.HtmlMeta") Page.Header.Controls.RemoveAt(i); thanks so much for your reply. i will update my code accordingly.
"marss" <ma***@ukr.net> wrote in message Abraham Andres Luna ???????:news:1162287267.707322.71790@m7g2000cwm.googlegroups.com... Show quoteHide quote > hello everyone, "The foreach statement is used to iterate through the collection to get> > this code only removes the first HtmlMeta control even though i loop > through > all of the controls: > > <%@ Page Language="C#" %> > <script runat="server"> > void Page_Load(Object Sender, EventArgs E) > { > foreach (Control ctl in Page.Header.Controls) > if (ctl.GetType().ToString() == > "System.Web.UI.HtmlControls.HtmlMeta") > Page.Header.Controls.Remove(ctl); > } > </script> > <html> > <head runat="server"> > <title>HtmlMeta Test Page</title> > <meta name="description" content="long description" /> > <meta name="keywords" content="keyword list" /> > </head> > <body> > Done! > </body> > </html> > > thanks for any help with this. the desired information, but should not be used to change the contents of the collection to avoid unpredictable side effects..." (MSDN) for(int i=Page.Header.Controls.Count-1; i>=0; i--) if (Page.Header.Controls[i].GetType().ToString() == "System.Web.UI.HtmlControls.HtmlMeta") Page.Header.Controls.RemoveAt(i); You could only remove first HtmlMEta control is because when you are
deleting the first HtmlMeta Control, the ControlCollection in the Page.Header will be reduced one, which would immediately out of the foreach. What you need to do is use the for statement, minus one on looping index whenever you call the Remove() method. Hope this helps, Alvin Chooi Microsoft ASP.NET Enthusiast http://alvinzc.blogspot.com
HyperLinkField and OnRowDataBound
How do I get a bitmap from the theme? visibly disable img link Can a repeater's ItemTemplate instantiate derived classes? Visual Development of Web Controls for SharePoint operations on string how to show dialogbox when click on datagrid template column? extending web controls Help on java script navigator for database available? |
|||||||||||||||||||||||