Good Day to everyone...

I need some help.. I just have a problem on how do I pass the value from the pop window to my main page.

I have a main page where it has two textbox namely DepartmentID, DepartmentName then I also put a Search button that when I click it the new window will pop up.

This customized pop window was designed using a datagrid and at the bottom was a SELECT button.

If I place my cursor to any row on the datagrid and Click the SELECT button, the data should pass to textboxes in my main page.

I am just new with ASP.NET c# and some of the function is Im not familiar, I need your help on this matter..

I would really appreciate any help you may offer.

Thanks in advance.

I am just new with ASP.NET c# and some of the function is Im not familiar, I need your help on this matter..

The solution to this problem is likely going to be client side related not server side. What you are asking is that when you select something on the "popup" window, you want that information to be updated in the textboxes of the main page. I see this being accomplished using JavaScript. If you tried to do this via ASP.NET, the problem is that ASP.NET is a server side scripting language. Things have to be done server side. So when you select something in the pop-up window you wouldnt be able to update an open window sitting in the user's browser.

In JavaScript, you have a property called Window.opener. Take a look at this for some information: http://www.w3schools.com/jsref/prop_win_opener.asp

In the pop-up page, you can send information back to the main window. Say you have a textbox with the id="txtBox1", then...

window.opener.document.getElementById("txtBox1").value = "Hello";

So from this point, on the client pop-up window, you need to do some work to get the value where you clicked on the select button and get this value to the window.opener.document... as shown above.

Before you get too deep into the woods, just try with a pop-up window that when you click a generic button, you exectute a function that runs this window.opener statement. Once you get that working, you can get deeper into figuring out how to integrate this with some of the asp.net controls.

Hi jorge, thank you so much for your time, I tried to follow your instruction, actually, before that I used the showdialogbox instead however the problem occurs when I put a search filter and page index in my child page... it open to new window which should not be.

So, when I saw your reply, I change my code a little bit using a "Window.Open()" and I've got this error

"window.opener.document' is null or not an object"

Below is my code for my parent page:

`<script type="text/javascript" type="text/javascript">
        function OpenChildWindow() {
            var resultObject = window.open("T_DepartmentList.aspx", "myWindow", "width=550,height=400") 


if (resultObject != null) 
 {
                               window.opener.document.getElementById("txtdeptid").value = resultObject.DeptID;
                window.opener.document.getElementById("txtdeptname").value = resultObject.DeptName;
            }
            return false;
        }
</script>`

Here's the code for my Child Page:

function CloseChildWindow(departmentid, departmentid) 
    {
                var resultData = new Object();
                resultData.DeptID = departmentid;
                resultData.DeptName = departmentid;
                window.returnValue = resultData;
                window.close();
                return false;
    } 

This is what I recommend for you...

start with this easy HTML example. Once you validate its working for you, convert the pages to .aspx and introduce your own controls and logic.

This works, just tested it..works fine from a web server.

main.html
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
         <input type="text" id="txtPopupValue" />
         <button onclick="javascript:return OpenPopup()">Select Item</button>

         <script>
              function OpenPopup() {
                   window.open("popup.html", "List", "scrollbars=no, resizable=no, width=400, height=280;");
                   return false;
              }
         </script>
    </body>
    </html>
popup.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<table>
     <tr>
          <th> </th>
          <th>Item Name</th>
     </tr>
     <tr>
          <td>
               <input type="submit" value="Select" onclick="javascript:SendValue('Item 1');" />
          </td>
          <td>Item 1</td>
     </tr>
     <tr>
          <td>
               <input type="submit" value="Select" onclick="javascript:SendValue('Item 2');" />
          </td>
          <td>Item 2</td>
     </tr>
</table>


<script>
function SendValue(val) {
     window.opener.document.getElementById("txtPopupValue").value = val;
     window.close();
}
</script>

</body>
</html>

Hi Jorge, thank you so much... you save my time..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.