Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to include js file through .cs????

How to include js file through .cs????

Scheduled Pinned Locked Moved ASP.NET
csharphelptutorialjavascriptxml
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anand Desai
    wrote on last edited by
    #1

    Hi friends, I am using .NET 2008 version. I want to include my js files, but not by standard way like '' but from .cs file. The problem is in above example, "companyname" can change and its comming from another xml file, which i am reading in .cs, so i have to give source of js file in cs.:confused: I have found 1 function "RegisterClientScriptInclude" in C#, but its not working. :( Please any one can help me to perform my task or please show me how to use "RegisterClientScriptInclude" function. Thanks for any help in advance. Happy Coding.:rose: Anand Desai Developer Atharva Infotech

    V A 2 Replies Last reply
    0
    • A Anand Desai

      Hi friends, I am using .NET 2008 version. I want to include my js files, but not by standard way like '' but from .cs file. The problem is in above example, "companyname" can change and its comming from another xml file, which i am reading in .cs, so i have to give source of js file in cs.:confused: I have found 1 function "RegisterClientScriptInclude" in C#, but its not working. :( Please any one can help me to perform my task or please show me how to use "RegisterClientScriptInclude" function. Thanks for any help in advance. Happy Coding.:rose: Anand Desai Developer Atharva Infotech

      V Offline
      V Offline
      vkrajeesh
      wrote on last edited by
      #2

      Hi Anand, try this line of code where u r currently writing the RegisterClientScriptInclude function,replace with this ClientScript.RegisterClientScriptBlock(typeof([ur .cs classname here]),"one"," "); company name is a variable that will include the name from ur xml file hope it helps Rajeesh K

      A 2 Replies Last reply
      0
      • A Anand Desai

        Hi friends, I am using .NET 2008 version. I want to include my js files, but not by standard way like '' but from .cs file. The problem is in above example, "companyname" can change and its comming from another xml file, which i am reading in .cs, so i have to give source of js file in cs.:confused: I have found 1 function "RegisterClientScriptInclude" in C#, but its not working. :( Please any one can help me to perform my task or please show me how to use "RegisterClientScriptInclude" function. Thanks for any help in advance. Happy Coding.:rose: Anand Desai Developer Atharva Infotech

        A Offline
        A Offline
        Anand Desai
        wrote on last edited by
        #3

        Dont bother for this question friends, i have solved it myself. all i did is:

        string jspath = "scripts/" + this.company + "/main.js";
        String csname = "PageLoadScript";
        Type cstype = this.GetType();
        ClientScriptManager cs = Page.ClientScript;
        cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl("~/" + jspath));

        Thanks friends and use this if any one is faciong this problem.

        Anand Desai Developer Atharva Infotech

        A 1 Reply Last reply
        0
        • V vkrajeesh

          Hi Anand, try this line of code where u r currently writing the RegisterClientScriptInclude function,replace with this ClientScript.RegisterClientScriptBlock(typeof([ur .cs classname here]),"one"," "); company name is a variable that will include the name from ur xml file hope it helps Rajeesh K

          A Offline
          A Offline
          Anand Desai
          wrote on last edited by
          #4

          Thanks Rajeesh, It is another good and shorter way, let me try by urs way, it'll save my time. Thanks for help.

          Anand Desai Developer Atharva Infotech

          1 Reply Last reply
          0
          • A Anand Desai

            Dont bother for this question friends, i have solved it myself. all i did is:

            string jspath = "scripts/" + this.company + "/main.js";
            String csname = "PageLoadScript";
            Type cstype = this.GetType();
            ClientScriptManager cs = Page.ClientScript;
            cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl("~/" + jspath));

            Thanks friends and use this if any one is faciong this problem.

            Anand Desai Developer Atharva Infotech

            A Offline
            A Offline
            Abhijit Jana
            wrote on last edited by
            #5

            just rember one more thing, when you have AJAX on that page you have to use ScriptManager, insted of ClientScriptManager

            cheers, Abhijit

            A 1 Reply Last reply
            0
            • A Abhijit Jana

              just rember one more thing, when you have AJAX on that page you have to use ScriptManager, insted of ClientScriptManager

              cheers, Abhijit

              A Offline
              A Offline
              Anand Desai
              wrote on last edited by
              #6

              Thanks buddy

              Anand Desai Developer Atharva Infotech

              1 Reply Last reply
              0
              • V vkrajeesh

                Hi Anand, try this line of code where u r currently writing the RegisterClientScriptInclude function,replace with this ClientScript.RegisterClientScriptBlock(typeof([ur .cs classname here]),"one"," "); company name is a variable that will include the name from ur xml file hope it helps Rajeesh K

                A Offline
                A Offline
                Anand Desai
                wrote on last edited by
                #7

                Thanks, your code helped me to include css file also, i was not able to include css file through cs by my code. All i did is:

                protected void Page_Init(object sender, EventArgs e)
                {
                Servicepath = "xmls/saltours/general/services.xml";
                string jspath = "scripts/companyname/main.js";
                String csname = "PageLoadScript";
                Type cstype = this.GetType();
                ClientScriptManager cs = Page.ClientScript;
                cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl("~/" + jspath));
                ClientScript.RegisterClientScriptBlock(typeof(PackageList), "one", "");
                ClientScript.RegisterClientScriptBlock(typeof(PackageList), "two", "");
                }

                and I got what was required.... Thanks,

                Anand Desai Developer Atharva Infotech

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups