locked
Inline WebResource access in .js file RRS feed

  • Question

  • User658386877 posted

    Hi, I find code like the following in SilderBehavior.js when reading AJAXControlToolkit's source code:

    <%=WebResource("AjaxControlToolkit.Slider.Images.slider_h_rail.gif")%>

    It is parsed into webresource url like  "WebResource.axd?d=DptK6M-vCS2T1NbGqsBigWUop5ryMj-Qwa6KVfKFx6QZ3kwRZyNQy81_SuOfrHjk0&t=633922522053672279" at runtime.

    But when developing ajax sever controls, I didn't find any way to do that in a .js file. (I know about accessing webresource in C#, but I want to know how to get in line "<%=WebResource("AjaxControlToolkit.Slider.Images.slider_h_rail.gif")%>" parsed.)

    Could anyone tell me how to get "<%=WebResource("AjaxControlToolkit.Slider.Images.slider_h_rail.gif")%>" parsed or did AJAXControlToolkit do something special?

    Thanks a lot.

    Tuesday, October 27, 2009 11:34 PM

Answers

  • User-2139489267 posted

    I don't know how they are referring page controls in external javascript file.

    but what i usually do to solve this problem is to have below function in my particular page

            //this function will return rendered id of the controls
            //to external javascript file
            function GetObj(id) {
                var val = "<%=HiddenField1.ClientID%>";
                val = val.replace("HiddenField1", id);
                return document.getElementById(val);
            }

    and i call this function in my external JavaScript file by passing control name like GetObj('txtname'); and it works perfectly.

    Because <%%> executes server side code and it won't work in external JavaScript file.

    I hope this helps!! [:)]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2009 4:22 AM

All replies

  • User377791177 posted

    The guy here seems to have developed a console application to findout the resources used by an ajaxtoolkit control


    Wednesday, October 28, 2009 3:34 AM
  • User-2139489267 posted

    I don't know how they are referring page controls in external javascript file.

    but what i usually do to solve this problem is to have below function in my particular page

            //this function will return rendered id of the controls
            //to external javascript file
            function GetObj(id) {
                var val = "<%=HiddenField1.ClientID%>";
                val = val.replace("HiddenField1", id);
                return document.getElementById(val);
            }

    and i call this function in my external JavaScript file by passing control name like GetObj('txtname'); and it works perfectly.

    Because <%%> executes server side code and it won't work in external JavaScript file.

    I hope this helps!! [:)]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2009 4:22 AM
  • User658386877 posted

    Thank you, gentlemen.

    Yes it was so strange that <%%> is in external JavaScript file. 

    Seems they did something in their own script manager.

    Wednesday, October 28, 2009 4:30 AM
  • User-2139489267 posted

    If explanation had helped you, mark the post as answer :)

    Thursday, October 29, 2009 1:34 AM