I'm trying to use an Embedded Resource Image in my custom Control, but it does not work.
Steps I done:
1) Create an Folder inside the Project (Resources);
2) Add the Image "test.gif";
3) Change the attribute "Build Action" to "Embedded Resource" on File Property Tab;
4) Add, on AssemblyInfo.vb: <Assembly: WebResource("<My Namespace>.Resources.test.gif", "image/gif", PerformSubstitution:=True)>;
5) On CreateChildControl I add:
(...)
Dim img as new Image
img.ImageUrl = Me.Page.ClientScript.GetWebResourceUrl(Me.GetType(), "<My Namespace>.Resources.test.gif")
(...)
Me.controls.add(img)
I already tried another stuffs, clean my browser cache and other suggestions. The <IMG ... /> tag appears on page source, but the image does not appear.
From your description, it seems that you are unable to load the embedded resource ,right?
Could you please make sure that the namespace is correct? Or if the resource matches DefaultNamespace.Filename.Extension. Besides, try to follow the article below:
I saw your post, and I had the same problem but figured it out. Part namespace and part GetType(). The namespace is the exact name you typed in the project application tab, root namespace. properties box.
I had to dump the web resource stuff and folder Resource, and place all the images in the project regular style, then tag them as embedded resources.
Hope it helps, It's frustrating trying to figure it out. All the different examples become confusing.
Protected Overrides Sub Render()
Dim cs As ClientScriptManager = Me.Page.ClientScript
Dim rsType As Type = Me.GetType()
ibSoundLink = New ImageButton
ibSoundLink.ImageUrl = cs.GetWebResourceUrl(rsType, "ICE5Software.teamRoster.PlayAudioButton.gif")
ibSoundLink.AlternateText = "Hover to play introduction"
ibSoundLink.Attributes.Add("onmouseover", "soundManager._writeDebug('<b>Demo 1a</b>'); soundManager.play('mySound0','/teamRoster/SoundFiles/CRASH_1.mp3');")
ibSoundLink.CausesValidation = False
ibSoundLink.OnClientClick = "soundManager._writeDebug('<b>Demo 1a</b>'); soundManager.play('mySound0','" & [SoundSource] & "');"
Controls.Add(ibSoundLink)
ibSoundLink.RenderControl(writer)
End Sub
I could not get the resource image to work. I had to place the images in the root folder, or the same place the web custom control is, an change the attribute again to embeded resource. Then I had to delete the resources that were registered so that the
images are just file taged embedded content.
I did some new tests and discover that my problem is VB. Unfortunately, company I work uses only VB.
I just finish the "last" test with resources. I create 2 identical projects in VB and C#. Both have one image, marked as Embedded Resource, one AssemblyInfo with reference to the image embedded resource and one Class.
The VB Project has the Root Namespace "MyNamespace.ResourceTestVB"
The C# Project has the Default Namespace "MyNamespace.ResourceTestCS"
VB Class
Imports System
Imports System.Web.UI.WebControls
Public Class MyCustomControl
Inherits CompositeControl
Protected Overrides Sub CreateChildControls()
Dim img As New ImageButton
img.ImageUrl = Me.Page.ClientScript.GetWebResourceUrl(Me.GetType(), "MyNamespace.ResourceTestVB.Resources.Sunset.jpg")
Me.Controls.Add(New System.Web.UI.LiteralControl("'CustomControlVB':<br />"))
Me.Controls.Add(img)
MyBase.CreateChildControls()
End Sub
End Class
C# Class
using System; using System.Web.UI.WebControls;
namespace MyNamespace.ResourceTest { public class MyCustomControl:System.Web.UI.WebControls.CompositeControl { protected override void CreateChildControls() { ImageButton img = new ImageButton(); img.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "MyNamespace.ResourceTestCS.Resources.Sunset.jpg"); this.Controls.Add(new System.Web.UI.LiteralControl("'CustomControlCS':<br />")); this.Controls.Add(img);
base.CreateChildControls(); } } }
Is VB a problematic language to use image (or others content) embedded resource?
Another question that I didn't found answer: What the difference between
Default (C#) and Root (VB) Namespaces?
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
<DefaultProperty("Text"), ToolboxData("<{0}:Test runat=server></{0}:Test>")> _
Public Class Test
Inherits WebControl
Protected Overrides Sub CreateChildControls()
Dim cs As ClientScriptManager = Me.Page.ClientScript
Dim rsType As Type = Me.GetType()
Dim img As New ImageButton
img.ImageUrl = cs.GetWebResourceUrl(rsType, "ICE5Software.teamRoster.PlayAudioButton.gif")
Me.Controls.Add(img)
MyBase.CreateChildControls()
End Sub
End Class
According your examples and tests I had done, then I conclude that the images (or other resources) must be in project root. That's correct?
All examples I tried, my images was in Resource folder in both VB and C# projects, but in C# it works. When I change (in VB) to root folder it works fine.
danfcosta
Member
57 Points
27 Posts
"Page.ClientScript.GetWebResourceUrl" does not work
Feb 29, 2008 05:26 PM|LINK
Hi all,
I'm trying to use an Embedded Resource Image in my custom Control, but it does not work.
Steps I done:
1) Create an Folder inside the Project (Resources);
2) Add the Image "test.gif";
3) Change the attribute "Build Action" to "Embedded Resource" on File Property Tab;
4) Add, on AssemblyInfo.vb: <Assembly: WebResource("<My Namespace>.Resources.test.gif", "image/gif", PerformSubstitution:=True)>;
5) On CreateChildControl I add:
I already tried another stuffs, clean my browser cache and other suggestions. The <IMG ... /> tag appears on page source, but the image does not appear.
What I'm doing wrong?
Thanks!
Nai-Dong Jin...
All-Star
41630 Points
3558 Posts
Re: "Page.ClientScript.GetWebResourceUrl" does not work
Mar 03, 2008 04:20 AM|LINK
Hi,
From your description, it seems that you are unable to load the embedded resource ,right?
Could you please make sure that the namespace is correct? Or if the resource matches DefaultNamespace.Filename.Extension. Besides, try to follow the article below:
http://aspnet.4guysfromrolla.com/articles/080906-1.aspx
Thanks.
danfcosta
Member
57 Points
27 Posts
Re: "Page.ClientScript.GetWebResourceUrl" does not work
Mar 03, 2008 01:59 PM|LINK
Hi Michael,
The Namespace is exactly the same (with lower and upper case).
Before I post this question, I already had seem some articles, including you mentioned above.
I tried to change the Namespace with all possible combinations, but it wont work.
My project (VB), was the Namespace, e.g. "MyNameSpace.MyProject". I already try to use (in AssemblyInfo.vb and MyCustomControl):
jkirkerx
Contributor
3750 Points
873 Posts
Re: "Page.ClientScript.GetWebResourceUrl" does not work
Mar 04, 2008 11:01 PM|LINK
I saw your post, and I had the same problem but figured it out. Part namespace and part GetType(). The namespace is the exact name you typed in the project application tab, root namespace. properties box.
I had to dump the web resource stuff and folder Resource, and place all the images in the project regular style, then tag them as embedded resources.
Hope it helps, It's frustrating trying to figure it out. All the different examples become confusing.
In the assembly info I placed
<Assembly: System.Web.UI.WebResource("ICE5Software.teamRoster.PlayAudioButton.gif", "image/gif")>Protected Overrides Sub Render() Dim cs As ClientScriptManager = Me.Page.ClientScript Dim rsType As Type = Me.GetType() ibSoundLink = New ImageButton ibSoundLink.ImageUrl = cs.GetWebResourceUrl(rsType, "ICE5Software.teamRoster.PlayAudioButton.gif") ibSoundLink.AlternateText = "Hover to play introduction" ibSoundLink.Attributes.Add("onmouseover", "soundManager._writeDebug('<b>Demo 1a</b>'); soundManager.play('mySound0','/teamRoster/SoundFiles/CRASH_1.mp3');") ibSoundLink.CausesValidation = False ibSoundLink.OnClientClick = "soundManager._writeDebug('<b>Demo 1a</b>'); soundManager.play('mySound0','" & [SoundSource] & "');" Controls.Add(ibSoundLink) ibSoundLink.RenderControl(writer) End Subdanfcosta
Member
57 Points
27 Posts
Re: "Page.ClientScript.GetWebResourceUrl" does not work
Mar 05, 2008 12:51 PM|LINK
Well, I think that this question is unsolved. To release any doubts, I do this, but the images didn't appear.
I already create a new Project, with an resource image and one page. The problem is the same.
The resource image really works?
jkirkerx
Contributor
3750 Points
873 Posts
Re: "Page.ClientScript.GetWebResourceUrl" does not work
Mar 05, 2008 04:10 PM|LINK
I could not get the resource image to work. I had to place the images in the root folder, or the same place the web custom control is, an change the attribute again to embeded resource. Then I had to delete the resources that were registered so that the images are just file taged embedded content.
Post your code if you want to make it work.
danfcosta
Member
57 Points
27 Posts
Re: "Page.ClientScript.GetWebResourceUrl" does not work
Mar 05, 2008 07:45 PM|LINK
I did some new tests and discover that my problem is VB. Unfortunately, company I work uses only VB.
I just finish the "last" test with resources. I create 2 identical projects in VB and C#. Both have one image, marked as Embedded Resource, one AssemblyInfo with reference to the image embedded resource and one Class.
VB Class
C# Class
Is VB a problematic language to use image (or others content) embedded resource?
Another question that I didn't found answer: What the difference between Default (C#) and Root (VB) Namespaces?
Thanks for all!!!
Danilo
jkirkerx
Contributor
3750 Points
873 Posts
Re: "Page.ClientScript.GetWebResourceUrl" does not work
Mar 05, 2008 10:14 PM|LINK
working code
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Text Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls <DefaultProperty("Text"), ToolboxData("<{0}:Test runat=server></{0}:Test>")> _ Public Class Test Inherits WebControl Protected Overrides Sub CreateChildControls() Dim cs As ClientScriptManager = Me.Page.ClientScript Dim rsType As Type = Me.GetType() Dim img As New ImageButton img.ImageUrl = cs.GetWebResourceUrl(rsType, "ICE5Software.teamRoster.PlayAudioButton.gif") Me.Controls.Add(img) MyBase.CreateChildControls() End Sub End Classdanfcosta
Member
57 Points
27 Posts
Re: "Page.ClientScript.GetWebResourceUrl" does not work
Mar 06, 2008 12:48 PM|LINK
Hum...
According your examples and tests I had done, then I conclude that the images (or other resources) must be in project root. That's correct?
All examples I tried, my images was in Resource folder in both VB and C# projects, but in C# it works. When I change (in VB) to root folder it works fine.
Very strange! [^o)]
I'll do more tests to try to find something else.
Thank you very very much !!!!!! [:D]
jkirkerx
Contributor
3750 Points
873 Posts
Re: "Page.ClientScript.GetWebResourceUrl" does not work
Mar 06, 2008 05:54 PM|LINK
I have no clue why it did not work in the Resource Folder. Mine is modeled from a CS example I found from MSDN.
But you have to get it to work first, then you can take it to the next level.
If someone wishes to elaborate on that, please feel free to post your suggestion or knowledge of proper use of the resource folder.
Make it a great day!