0

How to pass value from pop up window to hidden text box in parent page. When the text box are visible, the values are correctly displayed in the main page. But when I make the text box hidden, the values are not correctly passed from child to parent page.

// main page
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script language="javascript" type="text/javascript">
            function OpenWindow(sender, args) {                
                var areaName = $find("<%= txtArea.ClientID %>").get_value(); 
                retVal = window.open("show_area.aspx?areaName=" + areaName, null, "left=150px,menubar=no, top=150px, width=800px, height=570px, scrollbars=yes, status=no, resizable=no");               
                retval.focus();
        }
        </script>
</telerik:RadCodeBlock>
<table>
<tr>
    <td> Area Name: </td>
    <td> 
        <telerik:RadTextBox ID="txtArea" runat="server"></telerik:RadTextBox>       
    </td>
    <td>
        <telerik:RadButton ID="btnsearch" Text="Search" runat="server" AutoPostBack="false" OnClientClicked="OpenWindow" > </telerik:RadButton> 
        <telerik:RadTextBox ID="txtAeraId" runat="server" />
    </td>
</tr>
</table>

pop up page

// pop up page
 <script language="javascript" type="text/javascript">
        function LinkToMainWindow(a, b) {
            try {

                debugger;
                window.opener.document.getElementById('ctl00_UserContentPlaceHolder_txtAeraId').value = a;
                window.opener.document.getElementById('ctl00_UserContentPlaceHolder_txtArea').value = b;
            }
            catch (e) { }
            self.close();
        }
    </script>   

/// code behind logic  /////

if (e.CommandName == "select_area")
            {
                ClientScript.RegisterStartupScript
                    (typeof(Page), "FillAddress", "<script language=JavaScript>LinkToMainWindow('" + area_code + "','" + area_name + "');</script>");
            }   

The above code is working fine. I get the correct value of txtArea & txtAeraId from the pop up window.

The problem occurs when I make "txtAeraId" visible="false", the values are not passed from child to parent page. I can not get the selected values from pop up page to txtArea and txtAeraId of the main page.

<telerik:RadTextBox ID="txtAeraId" runat="server" Visible="false" />

I tried debugging the javascript function LinkToMainWindow, it is working fine. But the values txtArea and txtAeraId are not retrieved correctly in the main page. why is it so?

user4221591
  • 2,084
  • 7
  • 34
  • 68

1 Answers1

1

telerik controls (actually, asp.net controls in general) with Visible="false" will prevent the "control" from being sent to the client in the first place, so, it wont exist at all, hence why you can't find it

try removing the visible=false and hide the element using a containing element which is hidden using (inline) CSS

<div style="display:none;">
  <telerik:RadTextBox ID="txtAeraId" runat="server" Visible="false" />
</div>
Jaromanda X
  • 53,868
  • 5
  • 73
  • 87