Reputation: 4028
Image img = new Image();
img.ImageUrl = "images/sample1.jpg?rnd=" + (new Random()).Next();
// added random for caching issue.
this.Controls.Add(img);
I get the error as
Cannot create an instance of the abstract class or interface 'System.Drawing.Image' --->Line 1
'System.Drawing.Image' does not contain a definition for 'ImageUrl' and no extension method 'ImageUrl' accepting a first argument of type 'System.Drawing.Image' could be found (are you missing a using directive or an assembly reference?) ---> Line2
The best overloaded method match for 'System.Web.UI.ControlCollection.Add(System.Web.UI.Control)' has some invalid arguments ---> Line3
Error 10 Argument '1': cannot convert from 'System.Drawing.Image' to 'System.Web.UI.Control'
Please help me to solve the error.
Upvotes: 0
Views: 5161
Reputation: 2354
It looks like you're trying to use the wrong Image class. Fully qualify it and it should work like you're expecting.
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = "images/sample1.jpg?rnd=" + (new Random()).Next(); // added random for caching issue.
this.Controls.Add(img);
Upvotes: 6