How to use Javascript a file from resources

Yesterday has spent n-oe in time to understand (to a word in msdn very crookedly this question it is described) and in an Internet infa was only at one forum, and that only krokha... We Admit{Allow} we kontrol what write that and we had desire to use dzhavaskriptom - we certainly can directly khardkodom write that that such (from msdn):



if (! cs. IsClientScriptBlockRegistered (cstype, csname2))

{

StringBuilder cstext2 = new StringBuilder ();

cstext2. Append (" <script type=text/javascript> function DoClick () {"};

cstext2. Append (" Form1. Message.value ='Text from client script. '} </");

cstext2. Append (" script> ");

cs. RegisterClientScriptBlock (cstype, csname2, cstext2. ToString (), false);

}


But imkho it only dust in a code....

It is possible to make much more beautifully:

1. We add dzhavaskript a file in resources of assembly

2. In properties added dzhavaskript a file it is established{installed} Build Action:Embedded Resource

3. In AssemblyInfo.cs such attribute [assembly is added: WebResource (" Controls. Resources. Script_include.js ", "application/x-javascript")] - I explain: Controls - a name of assembly, Resources - the folder in which lays my file, Script_include.js - a file.

4. In the control such code is added:



protected override void OnPreRender (EventArgs e)

{

base. OnPreRender (e);

Page. ClientScript. RegisterClientScriptResource (typeof (MyControl), " Controls. Resources. Script_include.js ");


}


All now in on your page you can cause any functions from file Script_include.js

I hope the given note will help you to understand with this simple but poorly documentary question.


Job with links - Construction of links with help JavaScript

Construction of links with the help javascript gives the programmer a wide opportunity for various " maneuvers and manipulations " with a code and if you use frames you without it simply to not do without.


For this purpose use the following design: href = " javascript: " onopenmylink (); "



<a href = " javascript: " onopenmylink (); "> my link </a>


That is clicking on the link you cause on execution{performance} own function onopenmylink () in which you define{determine} the order of performance of a code necessary for you.

Further between tegami <head> and </head> it is inserted kostrukcija <script language = "javascript"> </script> and in kostrukcii the executed code is inserted.



<script language = "javascript">

function onopenmylink ()

{

alert (" you have pressed the link! ");

document.form1.action = "jslink.html";

document.form1.submit ();

return true;

}

</script>