0

I want to pass the variable from html page to a hidden field in aspx page, I have a aspx form with code

    <div id="divFrameHolder" style="display: none">
       <iframe  src="inner/RegSelect.html"name="myIframe" id="myIframe" width="100%" height="200px" frameborder="0" onload="hideLoading()"> 
<asp:HiddenField   ID = "hidField"   runat="server"  value = " " /> 
     </iframe>
    </div>

and RegSelect.html has this code

<div id="tabs">

        <ul>

            <li style="font-family:'b nazanin';  font-weight:bold"><a onclick="use();" href="site"><i class="fa fa-picture-o fa-5x"></i><br />سایت</a></li>
            <li style="font-family: 'b nazanin'; font-weight: bold"><a onclick="use();" href="stor"><i class="fa fa-shopping-cart  fa-5x"></i><br />فروشگاه</a></li>
            <li style="font-family: 'b nazanin'; font-weight: bold"><a onclick="use();" href="blog"><i class="fa fa-comments  fa-5x"></i><br />وبلاگ</a></li>

        </ul>

        <section class="tabs-content" style="width:100%">

            <div id="site" style="width:100%" >

            </div>


            <div id="stor">

            </div>
            <div id="blog">

            </div>
</section>

    </div>
<script>

        $('#tabs a').click(function (e) {
            var f = $(this).attr('href');
            alert(f);
            window.opener.location.href = "RegForm.aspx?" + "val=" + f
            //var c = $('#myIframe').contents().find('#HF1').val();
            //alert(c);
            //alert($('#myIframe #HF1').val());
            //$('  #HF1').val(f);          
        });
    </script>

Now, I want get var f in aspx page? Can I get the variable from html page into aspx page?

sadeq
  • 59
  • 9
  • You need to clarify your question. It seems you are asking how to _set_ a value of an `input` field from some _client side_ event which makes it no different than any _client side_ method of doing so, *vs* obtaining data from a `request` - query string or POST data payload.... – EdSF Jan 30 '16 at 16:31

2 Answers2

0

You can use Request.QueryString to get the value of an URL parameter

Retrieve GET variables from URL in ASPX

Community
  • 1
  • 1
pharkasbence
  • 957
  • 3
  • 9
  • 25
0

Seems like you want to pass a variable from the html page in the IFrame to a hidden field in the page containing the IFrame.

Accessing IFrame content using jQuery as explained here: how to access iFrame parent page using jquery?

Note: ASP.NET WebForms has a setting that determines how ID's are generated for a control. See Here Make sure your hidden field's id mode is static.

Also understand that ASP.NET generates ID's to prevent collisions. Use an ID for your hidden field that you know will be unique on the page.

<asp:HiddenField ID="hidField" ClientIDMode="Static" runat="server" value=" " />

Use this to access the hidden field in the aspx page:

   $('#tabs a').click(function (e) {
        var f = $(this).attr('href');
        alert(f);
        window.opener.location.href = "RegForm.aspx?" + "val=" + f

        $('#hidField', window.parent.document).val(f);

        //var c = $('#myIframe').contents().find('#HF1').val();
        //alert(c);
        //alert($('#myIframe #HF1').val());
        //$('  #HF1').val(f);          
    });

Note that hidField needs to be a dom element in the containing aspx page.

ASPX

<div id="divFrameHolder" style="display: none">
   <iframe  src="inner/RegSelect.html"name="myIframe" id="myIframe" width="100%" height="200px" frameborder="0" onload="hideLoading()"> 
 </iframe>

 <input type="hidden" id="hidField" />

</div>
Community
  • 1
  • 1
drizzie
  • 3,351
  • 2
  • 27
  • 32