Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
Finding HTML Control on Page loaded into tab
posted

I am trying to find an image button located in a page contained with in a WebTab. I want to click the button from Javascript when the user selects the tab. I have the client side event firing and can see the tab using getTabAt, but I cannot figure out how to find the image button when it located in an aspx page instead of being a control placed inside the form.

This code works when the control is located in the tab, but does not when the control is located in a page that is loaded into the tab:

       var tab = $find("<%=WebTab1.ClientID%>");
        var tabIndex = e.get_tabIndex();

        if (tabIndex == 1) {
            var imgButtonId = tab.getTabAt(tabIndex).findChild("ImageButton1").id;
            var imgButton = document.getElementById(imgButtonId);
            imgButton.click();
        }

Any help would be appreciated.

Thanks

Brent

 

  • 24497
    Suggested Answer
    posted

    Hi Brent,

    If you use ContentUrl, then tab uses iframe to render it. There is method/property of tab item get_iframe(). So, if ContentUrl is local, then you probably will get access to its document and can find child element from that document. Below is example (with skipped validations for nulls).

    var tabItem = tab.getTabAt(tabIndex);
    var iframe = tabItem.get_iframe();
    var doc = iframe.contentWindow.document;
    var elem = doc.getElementById('ImageButton1');

    <I think similar will be added in newer versions to implementation of findChild.>