Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

js in resx

  Asked By: Kiswar    Date: May 25    Category: Asp.net    Views: 655
  

I'm developing a custom server control, and whant to put the whole .js file
in assembly resource files.
And than send it to client like <script src="something"/>, and not with
RegisterClientScript.

Is it possible? Can anyone point me to some tutorial about it.

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Danny Perkins     Answered On: May 25

Of course you can. You do the rendering of your custom  control and you're
allowed to put  any tags and functionality inside of it. Probably it's best to
make some public property of type string scriptFolder that you enter to connect
to correct folder with the js file... I'd do it that way. But there may be
things I don't know behind this, that you know...

 
Answer #2    Answered By: Riley-jack Johnson     Answered On: May 25

Well, yes, that's one side of the problem. But when the control  is for sale,
not just for internal use, it's better to set it all in one dll, and the
client-script can be written and in resource  files. Than I can embbed this
script string in my html output. But I got better performance when the
JavaScript file is separeted, and can be cashed at client  browser. So I was
wondering to somehow use resource files  to pack it all, but than on
run-time, make a separete .js and send  it to browser.

 
Answer #3    Answered By: Kawthar Malik     Answered On: May 25

check for information about IE WebCOntrols which probably use same technique...
This way you'll maybe find useful info...

 
Answer #4    Answered By: Anthony Smith     Answered On: May 25

Change the property of the JS file to Embedded Resource.

Extract it with this.(add ref to System.Reflection)


Assembly asm = Assembly.GetExecutingAssembly();
if (asm != null)
{
// create stream to the embedded file(change js file name to what suits
you)
Stream stm = asm.GetManifestResourceStream(asm.GetName().Name + "." +
"JavaScript1.JS");
StreamReader reader = new StreamReader(stm);
// read it in
string _clientScript = reader.ReadToEnd();
// clean up
reader.Close();
stm.Close();
}

_clientScript now contains the JS.

 
Answer #5    Answered By: Edna West     Answered On: May 25

don't know if it helps but I've just done something similar(ish) ... I had a
class for a large jscript and simply wrote to a label.


namespace yournamespace{
using System;
public class JScript
{
private string str = "";

public JScript()
{
}
public string getjs()
{
str +="\n";
str +=" <SCRIPT language=\"javascript\">\n";
str +="<!--\n";
str +=" ......... blah blah blah\n";
str +="-->\n";
str +=" </SCRIPT>\n";
return str;
}

}
}

Label mylabel = new Label();
JScript myjs = new JScript()
mylabel.Text = myjs.getjs();

Not quite the same as what you want but it works ... and you can pass it
parameters if you wanted.

 
Didn't find what you were looking for? Find more on js in resx Or get search suggestion and latest updates.




Tagged: