0

I have HTML page having iframe in it.

I am taking asp.net page in ifrmae. That asp.net page also have a master page.

I am not able to fetch button text of my asp.net page in my html page

please suggest javascript/jquery

Thanks in advance..

this is my iframe in my html page

<iframe runat="server" scrolling='no' frameborder='0' id="iframe1" style="width: 100%">

i am assigning path to iframe in this way

document.getElementById('iframe1').src = "default.aspx"

where button is in default.aspx..this page also have a master page

5
  • You want to access the button inside an iframe from an aspx page? Commented Jun 12, 2014 at 5:25
  • from html page where iframe is Commented Jun 12, 2014 at 5:26
  • can you provide code for Button and Iframe. so we can know name and other attributes. Commented Jun 12, 2014 at 6:15
  • and what is the code for button? Commented Jun 12, 2014 at 6:33
  • please see my update above Commented Jun 12, 2014 at 6:35

2 Answers 2

1

KarthikManoharan is Leading you to the right way...

but what I suppose missing is, ID of the Button. Dynamically your Button ID is changed by the server every time you compile application.

So you need to prevent that first by adding ClientIDMode="Static" to your button. like :

<asp:Button ID="Button1" runat="server" Text="Button" ClientIDMode="Static" />

now you can access this button in your IFrame like:

 $('#iframe1').contents().find('#Button1')          // Access Button

 $('#iframe1').contents().find('#Button1').html()   // Return Text of Button

 $('#iframe1').contents().find('#Button1').click(function(){       });  // Events

Try this code. and let us know if you find any discrepancy.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your response...html() is giving null and click is giving error access is denied..please suggest some thing
1

try this one,

 $(document).ready(function () {
        document.getElementById("iframe1").src = "WebForm1.aspx";
        $('#iframe1').load(function () {
            var iframe = $('#iframe1').contents();

            iframe.find("#Button1").click(function () {
                alert("test");
            });
        });
    });

6 Comments

no its not working..it is giving error access is denied
hi i tried your code in other project..but problem is that in my project i am loading another project/solution...so i think i am getting error access is denied..please suggest
where did you place the code in default.aspx or iframe placed page?
in iframe placed page like this <script type="text/javascript" language="javascript"> $(document).ready(function () { $("input[type='button'][id$='btnSubmit']").click(function () { // alert(); $('#iframe1').contents().find('#ContentPlaceHolder1_btnback1').click(function () { alert('21212'); }); // $('#iframe1').contents().find(document.getElementById('ContentPlaceHolder1_btnback1')).click(function () { alert(); }); }); }); </script>
still it is working only if page is in same project..i am loading page of another project
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.