0

I'm having trouble to set a new attribute to the element, VS 2005 returns me the following error on the code below:

Error 1 No overload for method 'setAttribute' takes '2 'arguments Error 2 No overload for method 'setAttribute' takes '2 'arguments Error 3 No overload for method 'setAttribute' takes '2 'arguments

some of what can be the problem?

Thank you!

try
{
   IHTMLElementCollection AllElements = document.all;
   foreach (IHTMLElement Element in AllElements)
   {                   
      if (Element.tagName.ToUpper() == "IMG")
      {   
         if (Element.offsetHeight <= 40 && Element.offsetHeight >= 20)
         {
            if (Element.offsetWidth <= 160 && Element.offsetWidth >= 130)
            {
               Element.setAttribute("width", Element.offsetWidth);
               Element.setAttribute("height", Element.offsetHeight);
               Element.setAttribute("src", "images/newimage.png");
            }
         }
      }
   }            
}   
catch (Exception e)
{
   string erro = e.Message;
   System.Windows.Forms.MessageBox.Show(erro);
}
rene
  • 41,474
  • 78
  • 114
  • 152
Jean Coelho
  • 13
  • 1
  • 4
  • 2
    [RTFM](http://msdn.microsoft.com/en-us/library/aa752330(v=vs.85).aspx). setAttribute takes 3 arguments. – tnw Nov 11 '13 at 22:03
  • 3rd argument is optional... http://msdn.microsoft.com/en-us/library/aa752330(v=vs.85).aspx I can't find a problem in the code. however, there is a known bug in IE9 if that's the browser you're testing against. Otherwise, my only thought is maybe that Element is a reserved word in javascript and may cause some problems there. – Howard Renollet Nov 11 '13 at 22:09
  • 4
    VS2005 is stone cold old. C# v2 did not support optional arguments yet. – Hans Passant Nov 11 '13 at 22:09
  • I don't think the downvote and closevote are warranted. If you would've looked it up, you'd see that the third argument is optional. I don't think it's reasonable to expect that anyone should've known it's because of an (indirectly) older compiler version. – Jeroen Vannevel Nov 11 '13 at 22:14

1 Answers1

1

From MSDN: it appears that the third argument should be optional.

lFlags [in, optional] Type: long

LONG that specifies whether to use a case-sensitive search to locate the attribute. Can be one of the following values:

1

The case of strAttributeName is respected.

0

Match strAttributeName regardless of case.

You could try passing in 0 or 1.

Element.setAttribute("width", Element.offsetWidth, 0);
Element.setAttribute("height", Element.offsetHeight, 0);
Element.setAttribute("src", "images/newimage.png", 0);

Adding info from Hans' comment above (as suggested below):

"VS2005 is stone cold old. C# v2 did not support optional arguments yet. " - Hans Passant :)

Derek
  • 7,615
  • 5
  • 33
  • 58
  • You should specify that VS 2005 appearantly does not support optional arguments (old compiler version), per Hans Passants's comment. That's the real issue here. – Jeroen Vannevel Nov 11 '13 at 22:10