I have a custom control that has some embedded resources. I need to be able to reference some of the embedded material outside the control in JavaScript. So let's say I have an image file embedded in the control and I have a script outside the control that will do something with that file. How do I reference that file name outside the control?
Update: Not sure if this is even possible and I have not found any information on it. Anyone have an idea? Maybe I create functions inside the embedded JS to get access to those files?
Is this what you are looking for?? It looks like you can use the GetWebResourceURL from the ClientScriptManager class to do this.
Related
i have a page named Default.aspx and inside it i use an include virtual for the header. Is there a way i can use the controls inside that header in Default.aspx.cs? (Code Behind).It just doesn't recognize the code inside the include file, everytime i try to compile .net throws me a lot of errors related to unrecognized controls..
I know i can put my header inside the default page as usual, but i'd like to keep it in a separate file because it has a lot of content.
Thanks in advance..
Why would you want to do that?
Only reason I can come up with is reusability - and that could be solved by using a masterpage containing the header information or a usercontrol (or even a custom control)
I'd probably go with the masterpage solution - but your description of what and why you want to do as you do is a lite vague...
I am trying to build a C# .NET website that includes files based on DB input.
In PHP, this is simple, where I could do this very easily like this:
<?php include('inc/'.$filename);?>
Is there something similar to do this in C#? I've been trying to figure this out for a while, and can't find a simple solution. I know I can specify static files like this:
<%# Register Src="~/controls/blah.ascx" TagPrefix="test" TagName="blah" %>
... But I can't change the "blah.ascx" dynamically in the code-behind. This would work just fine if I always knew exactly what needed to be included.
Has anyone been able to accomplish this? Thanks!
You can easily add and read from files on the server. Not sure if you want to include existing files or make them on the fly.
Anyway, here's a link that explains how to read from a file on the server.
http://msdn.microsoft.com/en-us/library/94223t4d.aspx
Here is a link that explains how to load user controls dynamically.
http://msdn.microsoft.com/en-us/library/c0az2h86(v=vs.100).aspx
I finally found a solution that allows me to include any user control without having to register it in the .aspx page.
// Include external files here
// CustomControl variable can equal something like "home.ascx"
UserControl uc = (UserControl)Page.LoadControl("~/pages/" + CustomControl);
// PageCustomControl can be a Panel or PlaceHolder
PageCustomControl.Controls.Add(uc);
Based on code from http://forums.asp.net/t/1186225.aspx?Add+Web+User+Control+from+Code+Behind
I'm trying to use a resource (html file) located in a dll. With WinForms WebBrowser, when I navigate to the file, nothing happens, while with included AxSHDocVw.dll and SHDocVw.dll and AxWebBrowser, it works. Is the WinForms WebBrowser control somehow restricted or something? Can I make it to run res://?
See my post here: https://stackoverflow.com/a/15672462/1413201.
The basic gist is there are two types of resources in code files. You need to include a C style resource script to use the res protocol. Navigation errors are probably turned off in the WebBrowser control and therefore you don't see an error.
You can use the res protocol with IE to test if the resource is actually in the file and a C style resource editor just to double double check.
What I would assume, is that for security reasons, WinForms' WebBrowser control doesn't handle res:// links. It would make it very easy for someone to access resources which are contained within your DLLs which you may not want accessed.
If you want to implement the functionality yourself, then I'd recommend looking at the Assembly class and its use. It shouldn't be hard to parse a res:/// into your DLL path, load the assembly, search for the given resource and return that for the WebBrowser control.
I have a C# custom control that loads images from Resources.resx. I was loading this resources into the Project's Resources and then accessing them like:
ProjectNamespace.Properties.Resources.resourcename;
This works for one project but now I want to use my control in multiple projects.
What's the best way to handle this? Load the resources into the controls .resx? How can I access them from there? Or should I approach this completely differently?
It should work as is, even if your control is used from other projects.
The code generated by VS is a wrapper around the ResourceManager class, and it gives the assembly of your control as a constructor parameter. So, the ResourceManager always knows where to look for resources.
I would like to store some images to use in my C# application. They are png files and are currently in a folder with the dlls. Ideally I would like to have them included with the dll so i dont have to include the actual images with the installation.
What is the best way to do this?
I have though about resx but i am unsure as to the best way to go about it. Should I use create the resx file using another project, and then add it to the one I want to use it with?
Thanks in advance.
The easiest is to just add them to your current project and then set their Build Action property to Embedded. I believe that automatically adds them to a resource file and then you can access them using reflection.
Here's an article on retrieving them:
MSDN
Put them in a resource file. You can add it to the same project, no need to create another one.