Mike
Mike

Reputation: 17

Button Background Image using behind code Button.Style.Add()

Quick question. I am dynamically creating some buttons and basically want to add a background image to them in the code behind. Can someone tell me how its supposed to look like? I want to use the Button.Style.Add().

I tried Button.Style.Add("background-image","url(~/Uploads/Steak.jpg)"); but it did not work.

Upvotes: 0

Views: 78

Answers (2)

Ramesh Kumar
Ramesh Kumar

Reputation: 86

string strimgpath = "Uploads/Steak.jpg";
String strImgLocation = "url('" + strimgpath + "')";
idimage.Style.Add("background-image", strImgLocation);

Upvotes: 0

komal
komal

Reputation: 135

please use following code:

Button.Style.Add("background-image","url('~/Uploads/Steak.jpg')");

Add single quotes to the url

Upvotes: 1

Related Questions