Current theme
-
Hi, you mean like just the Name of the Pages' Theme? Within your UserControl, use
this.Page.Theme
to get or set the theme.
-
Hi, you mean like just the Name of the Pages' Theme? Within your UserControl, use
this.Page.Theme
to get or set the theme.
-
Hi, DeleteImageUrl is an exposed property of the user control.
public string DeleteImageUrl
{
get { return m_strDeleteImageUrl; }
set { m_strDeleteImageUrl = string.Format("~/App_Themes/{0}/{1}", this.Page.Theme, value); }
}this.Page is null here. Why ?
Has the UserControl been correctly added to a page before you set that property? When do you access the property? Is the control dynamically added or in markup?
-
Has the UserControl been correctly added to a page before you set that property? When do you access the property? Is the control dynamically added or in markup?
-
I placed the following line in a .skin file.
<UC:MultiFileUpload runat="server" UpperLimit="10" Rows="5" ListItemHoverColor="#F2D76A" DeleteImageUrl="Img/Delete.png" />
Ah, i see. You're working with skins and want the delete-image-url of your usercontrol to point to the correct image file of the current theme? Maybe the answer in this thread helps you?
-
Ah, i see. You're working with skins and want the delete-image-url of your usercontrol to point to the correct image file of the current theme? Maybe the answer in this thread helps you?
Correct. I followed your link, but I cann't see any answers. Basically what I do is the following: On the Page_Load event of the user control I inject javascript.
ScriptManager.RegisterStartupScript(this, typeof(Page), "MultiFileUploadScript", GetJavaScript(), false);
private string GetJavaScript()
{
StringBuilder JavaScript = new StringBuilder();
:
JavaScript.Append("var deleteImage = null;\n");
if (m_strDeleteImageUrl != string.Empty)
{
JavaScript.Append("deleteImage = new Image();\n");
JavaScript.AppendFormat("deleteImage.src = '{0}';\n", m_strDeleteImageUrl);
JavaScript.AppendFormat("deleteImage.setAttribute('alt','{0}');\n", m_strDeleteText);
}
:
return JavaScript.ToString();
}How can I make m_strDeleteImageUrl point to the correct theme image ? tia
-
Correct. I followed your link, but I cann't see any answers. Basically what I do is the following: On the Page_Load event of the user control I inject javascript.
ScriptManager.RegisterStartupScript(this, typeof(Page), "MultiFileUploadScript", GetJavaScript(), false);
private string GetJavaScript()
{
StringBuilder JavaScript = new StringBuilder();
:
JavaScript.Append("var deleteImage = null;\n");
if (m_strDeleteImageUrl != string.Empty)
{
JavaScript.Append("deleteImage = new Image();\n");
JavaScript.AppendFormat("deleteImage.src = '{0}';\n", m_strDeleteImageUrl);
JavaScript.AppendFormat("deleteImage.setAttribute('alt','{0}');\n", m_strDeleteText);
}
:
return JavaScript.ToString();
}How can I make m_strDeleteImageUrl point to the correct theme image ? tia
Can't you just set the images' filename (or subpath below the themefolder) in the setter of the DeleteImageUrl property of your usercontrol (without the string.format(..theme...) part)? Then, in the GetJavaScript() Method (which you call during Page-Load), you can build the correct path including the theme-folder by using Page.Theme, as Page should not be null there.
-
Can't you just set the images' filename (or subpath below the themefolder) in the setter of the DeleteImageUrl property of your usercontrol (without the string.format(..theme...) part)? Then, in the GetJavaScript() Method (which you call during Page-Load), you can build the correct path including the theme-folder by using Page.Theme, as Page should not be null there.
-
I already tried that. Even in the JavaScript method Page.Theme is null. Could it have to do the way I set my theme. In web.config I do :
<pages styleSheetTheme="Sunset">
<controls>
:
</controls>
</pages>tia
Oh yes, use Page.StyleSheetTheme instead. I really hope, the Page property of your control is not null..otherwise.. could you provide a sample project where it is not working? Cheers
-
I already tried that. Even in the JavaScript method Page.Theme is null. Could it have to do the way I set my theme. In web.config I do :
<pages styleSheetTheme="Sunset">
<controls>
:
</controls>
</pages>tia
-
Found it. In my JavaScript method I got the path as follows :
string strImageThemePath = string.Format("{0}/App_Themes/{1}/{2}", Page.Request.ApplicationPath, Page.StyleSheetTheme, m_strDeleteImageUrl);
Thanks Michael for your help.
Oh thank god =) Not a problem - glad it finally worked