开发者

How can I create and call a javascript function on a dynamically loaded user control?

开发者 https://www.devze.com 2023-01-01 13:41 出处:网络
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 pop

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.addressLine开发者_运维问答3 = $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


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

Jquery and Ajax Post issue


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消