0

I have two web form e.g. webform1 and webform2 . i am calling webform2 as dialog from webform1. I want to access ui element(e.g. hidden field) on click button event of dialog. When focus was on dialog (webform2) then i am able to get hidden filed value in console but when i click on dialog button and code executing button event in JS that time hidden field value becomes undefined.

$(function () {
    $("#dialog").dialog({
        autoOpen: false,
        modal: true,
        width: 950,
        title: "Add Lines to Manual Invoice",
        close: function () {
            $(this).dialog("close");
        },
        buttons: {

            okay: function () {

                console.log($('#HiddenField1').val()) // This is undefined while i want to access webform2 vlaue
                $(this).dialog("close");

            }
        },
        show: {
            effect: "slide",
            duration: 1500
        }
    });
    $("#opener").click(function () {
        $("#dialog").dialog('open');
        return false;
    });
});

i have load webform2 in iframe tag like below:

<button id="opener">open the dialog</button>
<div id="dialog" title="Dialog Title"><iframe style="border: 1px;height:700px;width:930px;" src="WebForm2.aspx"></iframe></div>
Always_a_learner
  • 1,254
  • 1
  • 8
  • 16
  • Sounds like the context is chaning, so the `this` is changing. Have you tried sending the data as a parameter of whichever function needs it? – Joel Hager May 01 '20 at 04:38
  • @JoelHager yes i had tried sending data with parameter and i had also tried some context selector like as $("#HiddenField1",parent.document) – Always_a_learner May 01 '20 at 04:46
  • Does this answer your question? [Pass a variable to JQuery UI dialog](https://stackoverflow.com/questions/14898765/pass-a-variable-to-jquery-ui-dialog) – Selim Yildiz May 01 '20 at 07:56
  • @SelimYıldız No .all are passing data from parent to child while i am looking data from child to parent. – Always_a_learner May 01 '20 at 09:24
  • I have resolved this . $(this).find('iframe').contents().find('[id="HiddenField1"]').val() – Always_a_learner May 01 '20 at 09:58

1 Answers1

0

I have resolved this with below line of code.

$(this).find('iframe').contents().find('[id="HiddenField1"]').val()
Always_a_learner
  • 1,254
  • 1
  • 8
  • 16