Click here to Skip to main content
15,896,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i am failing to pass the value from dropdownlist in the parent aspx form to textbox in the child aspx form

Parent javascript : The First script is to open the popup window
XML
   <script type="text/javascript">
    var popup;
      function NewCustOpn() {
     popup = window.open("NewCustomer.aspx","Popup",toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0,width=520,height=350,left = 250,top = 50");

}
  </script><pre lang="text">

This is the second script on the parent page to get the value of the dropdownlist
XML
  <script type = "text/javascript">
  function parentFunc()
  {
      return document.getElementById ("<%=DropDownList1.ClientID%>").value;
  }

</script><pre lang="text">

The child page javascript:
XML
  <script type = "text/javascript">
window.onload = function ()
{

    if(window.opener != null && !window.opener.closed)
    {
       var val = window.opener.parentFunc();
  var textbox = document.getElementById("<%=TextBox1.ClientID%>");
       textbox.Value = val;
    }
}
</script><pre lang="text">

When the popup opens TextBox1 is empty.
Posted

1 solution

Store ur dropdownlist selected value into one variable..
While opening Popup window send that variable as query string

open your window in code behind like below

C#
ScriptManager.RegisterClientScriptBlock(this.GetTye(), "openwindow", "<script> window.open(NewCustomer.aspx?customerId="+custID,"Popup","toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0,width=520,height=350,left = 250,top = 50");</script>", true);


and retrive above customerID value
by using below method

C#
function getQueryStrings() {
    //Holds key:value pairs
    var queryStringColl = null;
            
    //Get querystring from url
    var requestUrl = window.location.search.toString();

    if (requestUrl != '') {
        //window.location.search returns the part of the URL 
        //that follows the ? symbol, including the ? symbol
        requestUrl = requestUrl.substring(1);

        queryStringColl = new Array();

        //Get key:value pairs from querystring
        var kvPairs = requestUrl.split('&');

        for (var i = 0; i < kvPairs.length; i++) {
            var kvPair = kvPairs[i].split('=');
            queryStringColl[kvPair[0]] = kvPair[1];
        }
    }

    return queryStringColl;
}



above method returns query string details u can retrieve by using below code

C#
function myfunction() {
    var queryStringColl = getQueryStrings();
    alert(queryStrinColl['customerId']);
}
 
Share this answer
 
v4
Comments
Uriel Tinashe Patsanza 9-Jul-14 3:56am    
thank you,it has been puzzling me for sometime now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900