Click here to Skip to main content
15,889,874 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Loading image at run time in a custom control used in a page. How to code this? Pin
Frankidoze7-Nov-07 10:00
Frankidoze7-Nov-07 10:00 
GeneralRe: Loading image at run time in a custom control used in a page. How to code this? Pin
pmarfleet7-Nov-07 10:11
pmarfleet7-Nov-07 10:11 
GeneralRe: Loading image at run time in a custom control used in a page. How to code this? Pin
Frankidoze7-Nov-07 10:55
Frankidoze7-Nov-07 10:55 
GeneralRe: Loading image at run time in a custom control used in a page. How to code this? Pin
ahmet.ureten8-Nov-07 10:11
ahmet.ureten8-Nov-07 10:11 
AnswerRe: Loading image at run time in a custom control used in a page. How to code this? Pin
Guffa7-Nov-07 10:12
Guffa7-Nov-07 10:12 
GeneralRe: Loading image at run time in a custom control used in a page. How to code this? Pin
Frankidoze7-Nov-07 10:46
Frankidoze7-Nov-07 10:46 
AnswerI found the solution...Probably will write a paper about it Pin
Frankidoze7-Nov-07 12:05
Frankidoze7-Nov-07 12:05 
AnswerSolution Pin
Frankidoze7-Nov-07 12:34
Frankidoze7-Nov-07 12:34 
Here is the solution to

How to dynamically load images within a custom control with images embedded with it!

Context:
You have a project of type "Class Library" where you create your custom control MyCC.

1/ Add a new item: Resources File: Resources.resx

2/ Drag your images onto this resource file you had open. This will generate a sub folder named Resources containing all images dragged.

3/ Under "Solution Explorer", select each image file to change their "Build Action" property to "Embedded Resource".

4/ Set the image url property as follow in the overrided Render() or RenderControl() method depending which one you are using to generate the HTML of your custom control:
this._myImage.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "MyNameSpace.Resources.MyImage.gif"); 


The second param is of structure: [Namespace].[Resources Folder].[Resource File Name]

5/!!!! Carefull, the Namespace above and below has to match the default one defined in the project properties (Tab "Application").

6/ Last, either in your custom control .cs file or in your AssemblyInfo.cs, add this line for each image:
[assembly: System.Web.UI.WebResource("MyNameSpace.Resources.MyImage.gif", "image/gif")]

Conclusion:
Like this any page using your custom control will be able to display any image declared in your custom control.

Note: If you look at your page source when you run it, the src attribute of your image uses a WebResource.axd.

Enjoy.

If I have missed anything, I apologize.





"Nothing is lost, Nothing is created, Everything is transformed" Lavoisier

QuestionWhat are token ID's?? Pin
Goalie357-Nov-07 5:41
Goalie357-Nov-07 5:41 
QuestionIIS and .Net Issue - .aspx pages not pulling Pin
dboy2217-Nov-07 4:57
dboy2217-Nov-07 4:57 
AnswerRe: IIS and .Net Issue - .aspx pages not pulling Pin
Michael Sync7-Nov-07 5:32
Michael Sync7-Nov-07 5:32 
GeneralRe: IIS and .Net Issue - .aspx pages not pulling Pin
dboy2217-Nov-07 6:18
dboy2217-Nov-07 6:18 
GeneralRe: IIS and .Net Issue - .aspx pages not pulling Pin
Michael Sync7-Nov-07 6:21
Michael Sync7-Nov-07 6:21 
GeneralRe: IIS and .Net Issue - .aspx pages not pulling Pin
dboy2217-Nov-07 6:31
dboy2217-Nov-07 6:31 
GeneralRe: IIS and .Net Issue - .aspx pages not pulling Pin
dboy2217-Nov-07 8:42
dboy2217-Nov-07 8:42 
GeneralRe: IIS and .Net Issue - .aspx pages not pulling Pin
Michael Sync7-Nov-07 16:51
Michael Sync7-Nov-07 16:51 
QuestionBest layout for Subscriptions Page Pin
.NetRocker7-Nov-07 4:50
.NetRocker7-Nov-07 4:50 
AnswerRe: Best layout for Subscriptions Page Pin
Michael Sync7-Nov-07 5:54
Michael Sync7-Nov-07 5:54 
GeneralRe: Best layout for Subscriptions Page Pin
.NetRocker7-Nov-07 6:00
.NetRocker7-Nov-07 6:00 
GeneralRe: Best layout for Subscriptions Page Pin
Michael Sync7-Nov-07 6:14
Michael Sync7-Nov-07 6:14 
GeneralRe: Best layout for Subscriptions Page Pin
.NetRocker7-Nov-07 6:16
.NetRocker7-Nov-07 6:16 
GeneralRe: Best layout for Subscriptions Page Pin
Michael Sync7-Nov-07 6:39
Michael Sync7-Nov-07 6:39 
QuestionProblem with Login Control [modified] Pin
ocabrera707-Nov-07 4:33
ocabrera707-Nov-07 4:33 
QuestionProblem with UpdatePanel, ListBox, and the back button.. Pin
Dio227-Nov-07 4:25
Dio227-Nov-07 4:25 
QuestionProcess cannot access the file because it is being used by another process Pin
samerh7-Nov-07 3:48
samerh7-Nov-07 3:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.