F
Frédéric Mayot
Hi,
I'm trying to use web resources in ASP.NET 2.0. Unfortunately, it doesn't
seem to work for me.
Here are the steps I followed :
- Create a project WebSite
- Add a class library project to the solution
- Add the image "toto.gif" at the root of the class library
- Add to the AssemblyInfo.cs of the class library :
using System.Web.UI;
[assembly: WebResourceAttribute("toto.gif", "image/gif")]
- Add a class Class1 to the library (source at the end of the message)
- Use the control Class1 in the Default.aspx page
The control executes the code. The problem is that the image is not shown in
the navigator. The produced code is
<img
src="/WebSite7/WebResource.axd?d=IendFDRRH5UyJK83i7WG_yywijXHGsKhpzfqSIcgeGSWQKAj8LPTV0GZwrlZb6eH0&t=632486131940000000"
style="border-width:0px;" />
The thing is that I can't know if the image is well included when the
library is compiled. Is it normal that the compiler doesn't say anything if
I put a wrong path in the first argument of WebResourceAttribute ?
Any idea ?
Thanks,
Fred
namespace ClassLibrary1
{
public class Class1 : WebControl
{
public Image img;
protected override void CreateChildControls()
{
img = new Image();
Controls.Add(img);
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
img.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(string),
"toto.gif");
base.Render(writer);
}
}
}
I'm trying to use web resources in ASP.NET 2.0. Unfortunately, it doesn't
seem to work for me.
Here are the steps I followed :
- Create a project WebSite
- Add a class library project to the solution
- Add the image "toto.gif" at the root of the class library
- Add to the AssemblyInfo.cs of the class library :
using System.Web.UI;
[assembly: WebResourceAttribute("toto.gif", "image/gif")]
- Add a class Class1 to the library (source at the end of the message)
- Use the control Class1 in the Default.aspx page
The control executes the code. The problem is that the image is not shown in
the navigator. The produced code is
<img
src="/WebSite7/WebResource.axd?d=IendFDRRH5UyJK83i7WG_yywijXHGsKhpzfqSIcgeGSWQKAj8LPTV0GZwrlZb6eH0&t=632486131940000000"
style="border-width:0px;" />
The thing is that I can't know if the image is well included when the
library is compiled. Is it normal that the compiler doesn't say anything if
I put a wrong path in the first argument of WebResourceAttribute ?
Any idea ?
Thanks,
Fred
namespace ClassLibrary1
{
public class Class1 : WebControl
{
public Image img;
protected override void CreateChildControls()
{
img = new Image();
Controls.Add(img);
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
img.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(string),
"toto.gif");
base.Render(writer);
}
}
}