Designer support question

  • Thread starter Thread starter JKJ
  • Start date Start date
J

JKJ

I have a custom web control that needs a javascript file
to be included as part of the project. I want to have the
control automatically add the file in a specific folder to
the project when the control is added to the designer.
I've been looking for some kind of designer class, but
can't find anything that will enable me to do what I want
to do. Can anybody point me in the right direction?

Thanks!
 
this is a very reasonable request, but to my knowledge it
hasn't been done yet because the location of a file in
general is unknown.

you might look at the DesignOnlyAttribute documentation
and prompt the user to locate the file if it's not yet
part of the project. i'm not sure how you detect whether
it already is, but that should be doable.

while we're on the subject, perhaps a better way of doing
that is to package the javascript file in an assembly
with the control-- then it's sure to be there.
 
Hi,

As far as I know, you can specify a designer for any control with the
DesignerAttribute class. What you can do is inheriting from a standard
designer and overriding some methods to automatically add the JavaScript
file. Please note that I am not sure this is 100% possible - it's just a
direction to start digging towards.
 
I saw this in action via a control from Devmansion.com.
You add a control to the webform and supporting files are
automatically included in the project.

The *.js file is part of the project, and included as
contents. When the control is packaged, it will be in
the root directory of the library. I can reference the
file there.

I have also embedded the script itself in a resource file
and can read the contents of the .js into the .aspx at
runtime, but this increases the size of the page by a few
KB. I'd much rather have the control insert a <script>
tag with a src attrib, than the entire script itself.

I tried creating the file @ runtime and saving it in the
folder in the application root. If the folder doesn't
exist, then it creates that as well. If the file already
exists, then no action is taken. If by chance it gets
deleted, the control will detect that it is missing and
recreate the js file.

HOWEVER, to perform this action the ASP.NET worker
process needs to have write permissions on the directory,
and in the grand scheme of things, I think this could be
percieved as security issue.
 
Back
Top