views:

49

answers:

2

Hi Guys,

I have an ASP.Net page containing an IFrame. In the IFrame I load a html document. When the user clicks on a hyperlink in the content of the IFrame, I would need a callback to be called in the code-behind class of the ASP.Net page.

I guess that I need Ajax to do this but I'm not exactly sure about what I need to do. Could you give me some pointers?

By the way I'm fairly new to ASP.Net.

Thanks

A: 

Because the html document is not an aspx page it will not be able to trigger any code-behind. If you can change the page in the iframe make it an aspx page and handle the click on a LinkButton like you would do otherwise.

An other option is to change the link in the html page to call a custom aspx page that handles your needs, but that will redirect the html-page to the new aspx page.

Or indeed change the link to call a webservice through javascript (XMLHttpRequest) and let that webservice do what you wanted to do in code-behind.

Willem
I'll try to see if I can convert the html page to an aspx page. I don't know if this is easy to do because the html is generated on the fly. Thanks for your answer!
Christophe Keller
A: 

A lot of this depends on what it is you want to do specifically.

The problem you've got is that the DOM of the page in the iframe doesn't appear to be in the DOM of the calling page. All the calling page sees is the iframe tag as a closed tag, like an image tag. Some browsers will detect a click inside an iframe nested within a DIV as a click in the div so you have

<DIV id="iframediv">
  <Iframe blah...>
</DIV>

and then you might be able to use jQuery or similar to detect a click inside iframediv and do stuff.

The real solution would be to try not to use an iframe as, like I said, even this solution won't necessarily pay off. I can think of at least one scenario where not using an iframe is not an option so I'll leave that be.

Other than that Willem's suggestions also seem to be sound.

One Monkey
As I answered Willem I'll try to get rid of the iframe. Maybe convert the html in aspx control or something like that. Thanks for your input!
Christophe Keller