Frage

I have an iFrame, which contains a RadButton. The ID is btnTest.

Now, I try to call the click-method of this RadButton from outside of the iFrame. I have tried:

function SaveClick() {
    var iframe = document.getElementById('ifr');
    alert(iframe.id);
    var doc = iframe.contentWindow.document;
    if(doc) {
        alert('aaa');
    }
    //var btn = doc.getElementById('<%=btnTest.ClientID %>');
    var btn = $find('<%=btnTest.ClientID %>', doc);
    if(!btn) {
        alert('bbb');
    }
    btn.click();
}

but nothing is working.

I can get the iFrame (the id of the iFrame is showing in the first alert) and also 'aaa' is showing in the second alert. But I cannot get the btn (the third alert with 'bbb' is also showing because of the not in the if).

Can someone help me please, how to get the control?

War es hilfreich?

Lösung

Create a function in the page that you put in the iframe. This function will return a reference to the button.

var btn = iframe.contentWindow.getMyRadButton();
btn.click();

where getMyRadButton is something like

function getMyRadButton() {
 return $find("<%=RadButton1.ClientID%>");
}

Andere Tipps

You use onclick, for example:

document.getElementById("ele").onclick = function(){
    alert("Hello World");
}

document.getElementById("ele").onclick();

And you should have a function made for that elemenet for onclick.

http://jsfiddle.net/3RTGL/1/

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top