tags:

views:

35

answers:

1

i'm bind some image control dynamically. but don't set image url. When i using skin file and then set skinid, error shown (The 'SkinId' property can only be set in or before the Page_PreInit event for static controls. For dynamic controls, set the property before adding it to the Controls collection)

How to get virtual theme location ?

A: 

Set the SkinId on the markup

<asp:Image runat="server" id="LogoImage" SkinId="LogoImage" />

To set it programatically you need to set it up on the PreInit event

public void Page_PreInit(object sender, EventArgs e)
{
  LogoImage.SkinID = "LogoImage";
}

And here is a blog post for setting the SkinId Programatically http://blogs.conchango.com/simonevans/archive/2005/06/09/How-to-programmatically-assign-a-SkinID-to-a-control-while-using-a-master-page-in-ASP.net-2.0.aspx

Finally, if you are just looking for the folder, it depends on whether you are using a Theme or a StylesheetTheme.

var path = "~/App_Themes/" + Page.Theme + "/images";
var path = "~/App_Themes/" + Page.StylesheetTheme + "/images";

Update

If you doing this in a Grid use a custom binding method

<asp:Image runat="server" id="myImage" ImageUrl='<%# GetThemedImage(((Product)Container.DataItem).Image)%>' />

then in the code-behind

public string GetThemedImage(string image)
{
     return "~/App_Themes/" + Page.Theme + "/images/" + image;
}
bendewey
how to set SkinId dynamically?
ebattulga
i'm using grid and put image control on the template.First I'm get handle of image control.After I need to set image url on the Grid databinding event
ebattulga
I updated my answer, hopefully this helps
bendewey