Link to home
Start Free TrialLog in
Avatar of sspeedy00
sspeedy00Flag for United States of America

asked on

Taking Data From Pop-Up Window And Filling Textboxes On Main Page (with that data)

Hi Guys,

Let me explain.  There is a main page that has a button called 'Find Emp ID'.  WHen user clicks on it, it should pop up a window, ask for last name, do a search.  IF EMPLOYEE EXISTS, this is what should happen:

1. take last name, first name, emp id, work location and pass it back to the m ain page to fill out the text box fields
2.  close the popup window.

TO pop up the window, the main page has this code in page_load:
this.btnFindEmplid.Attributes.Add("OnClick", "window.open('FindEmployee.aspx', '', 'height=400, width=600');return false");

I"m not sure how to kill a window and pass back the data to the main page.  
TIA.
SOLUTION
Avatar of five22bags
five22bags
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sspeedy00

ASKER

five22bags,
Thanks for the article link, but I"m still having a hard time.  The article shows you how to get data from a grid; I'm pulling it from a db and need to return it.  Not sure how to go about it still.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Child .aspx.cs code has a public array which will hold emplid, first and last names.  It gets declared in the beginning of class.
This is the actual script:
<script type="text/javascript">
function UpdateParent(empid,lname,fname)
{
if (empid.length < 6)
{
window.opener.document.getElementById("tbEmplid").value = "0" + empid;
}
else
{
window.opener.document.getElementById("tbEmplid").value = empid;
}
window.opener.document.getElementById("tbLast").value = lname;
window.opener.document.getElementById("tbFirst").value = fname;


this.close();
}
</script>
 
This is how it gets called:

Page.RegisterStartupScript("Update", "<script language=JavaScript>UpdateParent(" +
userData[2].Trim() + ", " + userData[0] + ", " + userData[1] +
", " + ");</script>");
This line gets called but doesn't actually call the script.  The child window never closes and the fields on parent page never populate.
I am using IE7 unfortunately, but I've also tested in Firefox and no go.  What am I doing wrong?
Hi,

You have to remove the last comma in your code. The code should be like below.
Page.RegisterStartupScript("Update", "<script language=JavaScript>UpdateParent(" +userData[2].Trim() + ", " + userData[0] + ", " + userData[1]  + ");</script>");

Open in new window

raja,
Thanks for pointing that out, but I also had to surround the args with ", so I escaped quotes before and after each arg.
Here's what the function looks like now:

function UpdateParent(empid, lname, fname)
{
alert("1");
if (empid.length < 6)
{
alert("2");
window.opener.document.getElementById("tbEmplid").value = "0" + empid;
alert("3");
}
else
{
alert("4");
window.opener.document.getElementById("tbEmplid").value = empid;
alert("5");
}

alert("6");
window.opener.document.getElementById("tbLast").value = lname;
alert("7");
window.opener.document.getElementById("tbFirst").value = fname;
alert("8");


this.close();
alert("9");
}
 alerts 1 and 4 get executed, but nothing else.  So it thinks there is something wrong with the window.opener.document.getElementById line.  When I manually type in window, Intellisense pops up and I select opener, but after that period, I don't get any options.  So obviously I'm using this in the wrong manner..?
Can someone help me with this javascript part?  Would really appreciate it.  Never really have messed with JS, and now it's biting my butt.
Hi,

Are you using any MasterPage in that child page?
Hi,

Are you using MasterPage for Parent page?
raja,
The child page inherits from Syste.Web.UI.Page, but the parent page does use a Master Page.
Why do you ask?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
raja, you're awesome.  That worked.  There's one thing that's not working: apparently, all the alert boxes popped up, meaning it executes each line.  However, it doesn't work when it comes to this line in the script function:
this.close();
Then I tried window.close();
It sends data back to the main page, but doesn't close itself.  Ideas?
 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
raja, fantastic.  You rocked it and I learned a LOT from this.  Thanks!
Great, complete answers!
Thanks, glad to help.