views:

119

answers:

1

when i try to call a javascript function in a dynamically loaded user control, it cannot find the function specified. I have a user control for organizationDetails.ascx. In there, I am using modal popup extender to get some information from the user and then i verify the address through google and suggests the proper format. I am trying to use a java script for a function called for onBlur of a textbox but the mozilla firebug says that the function is not defined, which is not the case. It would be great if someone can help me out here.


EDITED: The javascript is on the ascx page in the beginning and the usercontrol is loaded using the base class to show the organization details and edit them.

The ascx page has the following tags in the panel which is called by the modal popup.

                <padrap:DropDownList    ID                  ="ddlStateID"
                                        onChange            ="setContextKey2()"
                                        runat               ="server" />

                            <br />                  
                <padrap:Label           ID                  ="lCity"
                                        Text                ="City: "
                                        AssociatedControlID ="tbrCity" 
                                        runat               ="server" 
                                        CssClass            ="col2"/>                       


                <asp:TextBox            ID                  ="tbrCity"
                                        onBlur              ="setContextKey2()"
                                        runat               ="server" />                        


              <br />

<script type="text/javascript">
    alert('i hate javascript');

     var dependentBehaviors = [
            'tbCity_ace_b'
        ];

        var address = {};
    function setContextKey2(){
    //some javascript
            address.addressLine1 = $get('<%=tbrAddressID1.ClientID %>').value;
            address.addressLine2 = $get('<%=tbrAddressID1.ClientID %>').value;
            address.addressLine3 = $get('<%=tbrAddressID1.ClientID %>').value;
            address.countryISO2 = $get('<%=ddlCountryID.ClientID%>').value;
            address.stateCode = $get('<%=ddlStateID.ClientID%>').value;
            address.city = $get('<%=tbrCity.ClientID%>').value;
            address.postalCode = $get('<%=tbrPostalCode.ClientID%>').value; */

            var contextStr = Sys.Serialization.JavaScriptSerializer.serialize(address)

            var behavior = $find('tbCity_ace_b')
            behavior.set_contextKey(contextStr);

            var behavior2 = $find('tbPostalCode_ace_b')
            behavior2.set_contextKey(contextStr);
    }
 </script>

The function for setContextKey2() is defined in the beginning of the page. Please let me know if you need some more information.

Thanks, Ratan

A: 

Hey this link might help. It is a very simular question

http://stackoverflow.com/questions/2901643/jquery-and-ajax-post-issue/2901647#2901647


EDITED

The problem is your ajax call is not registering your script tag. If you put the script on your main page and not the ascx then this will work. Or you can get the script tag from the ajax response and then register it with the dom.

John Hartsock
That is not exactly what I want.. if you look at the code I have attached.. None of the javascript on the control is loading.. Is it a bug in ajax?
Ratan
I tried the first method earlier but it did not work, how do I go with the latter? I am new with ajax..Thanks,Ratan
Ratan