+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Javascript and Sitefinity

Javascript and Sitefinity

4 posts, 0 answered
  1. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    09 Feb 2010
    Link to this post
    I've created a custom control with VS2005 and then added it in the web.config file. The ascx file is as below. I am not sure it is a correct way to implement js script in sitefinity. Can anyone point me to the right direction.

    <script type="text/javascript">
    var group = document.getElementById("group").value;

    window.onload = function(){
    document.getElementById("f1").src = MetricsWin();
    }

    function MetricsWin(){
    return  "http://test.com";
    }
    </script>

    Thanks,
    Pik
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Feb 2010
    Link to this post
    Hello Pik Lee,

    This is one of the possible ways - wrapping the script directly in the control template. You can create a separate js file and place it in a application folder. Then you can make a reference to this file using the code below

    HtmlGenericControl scriptControl = new HtmlGenericControl("script");
    scriptControl.Attributes.Add("type", "text/javascript");
    scriptControl.Attributes.Add("src", UrlSrc);
    this.Page.Header.Controls.Add(scriptControl);

    UrlSrc is the path to your js file. This is the better way to do it.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    09 Feb 2010
    Link to this post
    Thanks for the info. Can you tell me how do I include the example javascript's function in Sitefinity's control section?  I am trying to create a js function which is needed in multiple place. Or create a ascx file then include it in web.config.

    Thanks,
    Pik

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Feb 2010
    Link to this post
    Hello Pik Lee,

    Create a simple user control where you load the scripts you need. Then call the functions from the script that has already been loaded through your use/custom control. It is the same as with the way you use Client side API of RadControls for ASP.NET AJAX.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
Register for webinar
4 posts, 0 answered