Data binding expressions in javascript include files

Last post 07-04-2009 4:39 AM by Abdulla.AbdelHaq. 1 replies.

Sort Posts:

  • Data binding expressions in javascript include files

    07-03-2009, 1:46 PM
    • Participant
      1,214 point Participant
    • andieje
    • Member since 10-25-2005, 11:23 PM
    • Posts 381

     Hi

    I have some javascript that contains databinding expressions. I was trying to include this in my webpage as include file or by using RegisterStartUPScript

    Here is the javascript

    function ToggleStartDateCalendarPopup()
            {
                $find("<%= dpStartDate.ClientID %>").showPopup();
            }
            
            function ToggleEndDateCalendarPopup()
            {
                $find("<%= dpEndDate.ClientID %>").showPopup();
            }


     

    But then the page does not run and I get this error: Message: 'null' is null or not an object

    I presume this is because of the data binding expressions. Is there anything I can do to include this javascript externally?

    I tried putting the javascript in a usercontrol so that I could drop it on the pages that use this code but naturally the page wouldn't compile because the user control does not have a control called dpStartDate.

    Any help is much appreciated

    thanks

     

     

  • Re: Data binding expressions in javascript include files

    07-04-2009, 4:39 AM
    Answer

    you got two choices ... either you send the clientId of the control as argumant to the javascript function from the page .. or you need to use the "Javascript object oriented way" .. I mean you need to create a variables and properties for the javascript external file and then create object instance from that javascript file..

    like this ..

    function myJsClass(SomeControlClientID)
    {
        
        this.SomeControlObj = document.getElementById(SomeControlClientID);

    }


    myJsClass.prototype.ToggleStartDateCalendarPopup=function()
    {
        You can now use the control object here by calling the "SomeControlObj"
     variable which contain the object of the control

    EX:  this.SomeControlObj

    }


    Now in the page declare javascript object from that javascript class

    <script language='javascript'>

    var MyObjJs = new myJsClass('<%= TextBox1.ClientID %>');

    MyObjJs.ToggleStartDateCalendarPopup();


    </script>

    Plz remember to click "Mark as Answer" if this helped you.

    Abdulla AbdelHaq    MCTS, MCPD

    - My Articles on ASP Alliance
    - My Weblogs
    - My Sessions on JorDev User Group

    "Experience is simply the name we give our mistakes"
Page 1 of 1 (2 items)