sspeedy00
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.Attribu tes.Add("O nClick", "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.
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.Attribu
I"m not sure how to kill a window and pass back the data to the main page.
TIA.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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,f name)
{
if (empid.length < 6)
{
window.opener.document.get ElementByI d("tbEmpli d").value = "0" + empid;
}
else
{
window.opener.document.get ElementByI d("tbEmpli d").value = empid;
}
window.opener.document.get ElementByI d("tbLast" ).value = lname;
window.opener.document.get ElementByI d("tbFirst ").value = fname;
this.close();
}
</script>
This is how it gets called:
Page.RegisterStartupScript ("Update", "<script language=JavaScript>Update Parent(" +
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?
This is the actual script:
<script type="text/javascript">
function UpdateParent(empid,lname,f
{
if (empid.length < 6)
{
window.opener.document.get
}
else
{
window.opener.document.get
}
window.opener.document.get
window.opener.document.get
this.close();
}
</script>
This is how it gets called:
Page.RegisterStartupScript
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.
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>");
ASKER
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.get ElementByI d("tbEmpli d").value = "0" + empid;
alert("3");
}
else
{
alert("4");
window.opener.document.get ElementByI d("tbEmpli d").value = empid;
alert("5");
}
alert("6");
window.opener.document.get ElementByI d("tbLast" ).value = lname;
alert("7");
window.opener.document.get ElementByI d("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.get ElementByI d 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.
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.get
alert("3");
}
else
{
alert("4");
window.opener.document.get
alert("5");
}
alert("6");
window.opener.document.get
alert("7");
window.opener.document.get
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.get
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?
Are you using any MasterPage in that child page?
Hi,
Are you using MasterPage for Parent page?
Are you using MasterPage for Parent page?
ASKER
raja,
The child page inherits from Syste.Web.UI.Page, but the parent page does use a Master Page.
Why do you ask?
The child page inherits from Syste.Web.UI.Page, but the parent page does use a Master Page.
Why do you ask?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
this.close();
Then I tried window.close();
It sends data back to the main page, but doesn't close itself. Ideas?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
raja, fantastic. You rocked it and I learned a LOT from this. Thanks!
ASKER
Great, complete answers!
Thanks, glad to help.
ASKER
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.