Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window Refresher

Status
Not open for further replies.

quinnipiac0807

Programmer
Oct 25, 2004
38
US
Got the ddl working but here's my question. I have two pages, we'll say Page1.aspx and Page2.aspx. When you click something on page 1 it opens page 2 and you can make changes on page 2. So when you click ok on page 2 it brings you back to page 1 but i need page one to reload to show the changes. I don't know much javascript but i think that's how you have to do it. Does anyone know how? Thanks.
 
Yep.

Assumption: Page1 opens Page2 either with a JavaScript "window.open()", or by setting an href to Page2 with the target attribute set to "_blank".

You need to do this so that Page2 has a "self.opener" property referring back to Page1.

Then, in your code-behind, which runs when Page2's form is submitted, write out the following script block:

Code:
Response.Write(@"<script>self.opener.location.reload( true ); self.close()</script>");

When Page2 is submitted, the last thing your server code does is add a script to the response stream. When Page2 reloads, it will run this script which

1) Causes Page1 (self.opener) to reload, and
2) closes Page2

I do this in the following scenario:

Page1 is a Job Entry screen which contains a ddl of all customers. The user can enter a new customer at this point. There is an href which loads Page2, Customer Entry.

When they enter a new customer, I want Page2 to close, and Page1 to reload so that the new customer is in the ddl.

It works flawlessly.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
How are you coming back to page 1? If you navigate to it and not use the back (Link / Server.Transfer / Response.Redirect)- it should run the Page Load again and not be marked as a postback.

Hope this makes sense.



Hope everyone is having a great day!

Thanks - Jennifer
 
Just as example (nothing new from the above arguments) here is a snippet of java that I use to send variables to Page 2 from Page 1, process new input, and send new values from Page 2 to Page 1.

Inital event on Page 1 (button click):

Code:
<INPUT TYPE="button" VALUE="Y1" onClick="javascript:getY1();" style="font-size: 14px; font-weight: bold; color: #0000FF;" width="28px">

calling the java function:

Code:
function getY1(){   
 var strPg;
 strPg = "setY1.aspx?Y1Max=" + document.forms["frmChemHist"].elements["txtY1Max"].value + "&Y1Min=" + document.forms["frmChemHist"].elements["txtY1Min"].value + "&Y1Int=" + document.forms["frmChemHist"].elements["txtY1Int"].value
 ChildWindow = window.open(strPg , 'newWinY', "width=210,height=250,top=200,left=320,toolbars=no,scrollbars=no,status=no,resizable=no");    
}

and then re-submitting Page 2 with new variables and calling for the submittal of Page 1:

Code:
<script language="Javascript">
function ReturnY1(Y1Max, Y1Min, Y1Int){
var Y1Max;
var Y1Min;
var Y1Int;
window.opener.document.forms["frmChemHist"].elements["txtY1Max"].value = Y1Max;
window.opener.document.forms["frmChemHist"].elements["txtY1Min"].value = Y1Min;
window.opener.document.forms["frmChemHist"].elements["txtY1Int"].value = Y1Int;
window.opener.document.forms["frmChemHist"].submit();
window.close();
}      
</script>

Just a bit code; might help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top