tester
tester

Reputation: 23159

HtmlGenericControl("img") not generating proper image tag

in asp.net, I'm trying to generate an image tag with:

var img = new HtmlGenericControl("img");

it seems to generate <img></img>

How would I generate a normal image tag with asp.net/C#?

e.g.

<img/>

Upvotes: 2

Views: 3500

Answers (3)

lincolnk
lincolnk

Reputation: 11238

There's a specialized html control for the image element.

System.Web.UI.HtmlControls.HtmlImage

which generates the html you want.

Upvotes: 6

Gregory A Beamer
Gregory A Beamer

Reputation: 17010

Override the rendering method and use HtmlTextWriter.SelfClosingTagEnd to create a self closing tag?

Upvotes: 1

Robert Beaubien
Robert Beaubien

Reputation: 3156

You are creating it as a generic html control. Try using the Image control:

var img = new Image();

Upvotes: 1

Related Questions