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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remember Form Values on page reload 2

Status
Not open for further replies.

fly231

Programmer
May 29, 2005
24
GB
Hi,

I got a asp.net page (SignupForm.aspx) with some text fiels and a link on it.
When the link is clicked it opens up a new page(SelectNumber.aspx) on a new window.
I have a button on the new page(SelectNumber.aspx), when clicked reloads the parent page(SignupForm.aspx).

My problem is when it reloads the SignupForm.aspx page, it forgets the form values on the page.
Is there a simple way of remembering form values on a page reload ?

I would appreciate any help on this.

here's the line of code i use on the page to reload the parent page.
Code:
void OnButtonSubmit(Object sender, EventArgs e) 
{
RegisterClientScriptBlock("", "<script language='JavaScript'> opener.location.reload(); </"+"script>");
}


Thanks.
 
What's the purpose of the reload? Is it really necessary? One thing you could try is append the values that you want to restore on SingupForm.aspx to the querystring when you open SelectNumber.aspx via javascript ie.
Code:
window.open("SelectNumber.aspx?FName=" + FName + "&LName=" + LName,"myNewWindow",myWindowOptions);
Capture the querystring values and feed them to the javascript function on SelectNumber.aspx
After you call the reload from SelectNumber.aspx you could try
window.opener.frmSignup.FirstName.value=FName
window.opener.frmSignup.LastName.value=LName
of course you'll need to wrap your javascript in functions instead of one-liners.
If you find a work-around for the reload this becomes a non-issue.
Hope you get what I'm saying.
 
Hi,

Thanks for the response.

I understand what you are saying. But I was wondering if there's an easier way of doing it rather than manually remembering each form value and restoring them.
I think it could also be done using remembering the values of the form fields in sessions.

The purpose is I got a form and it'll have about 30 text fields and other form items, in the middle of it I need the user to search and select some phone numbers from a long list, this is where I open up a new window, where the customer can search and add values to the parent form.

Only problem is the when the parent form reloads it can't remember the form values that users entered earlier.

I know ASP.Net can remember values on post, and I thought it work the same on reload, but apparently it doesn't.

It would be great if there's an easier way of remembering the form values on reload.


Thanks.
 
But why reload the form at all? Just pass back the selected value and assign it to a textbox or what ever object you want.
 
But how can you pass a value to a page on the client machien without reloading it ?

I can let the user select and add the numbers they want on the new window but I think it's impossible to add it to the parent form without reloading it .

Thanks
 
you have to use javascript

Something like:
opener.document." + form.name + "." + dateFieldName + ".value= "your value here
 
I think you could use JavaScript for this. When the user selects a value on the pop-up page, a script would fire to insert that value into the proper form element on the parent page.

You don't need any server-side code for this, you eliminate the server reload, plus eliminate the need to reload the parent page.

JavaScript code on the child window would refer to "self.opener.document" to interact with elements on the parent form.

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Thanks Veep and jbenson001 for the suggestions.

I think I found a different way for doing it.
I thought of having an iframe in the parent form and having the link in there. So when the popup window calls the reload it just reloads the page in the Iframe and the form values on the page remains.

Once again I appreciate your help.

 
What's wrong with the JavaScript? You can completely avoid the reload and subsequent server round trip.

Parent Page
Code:
<html>
<head>
  <title>JavaScript Sample by tgreer</title>
  <script type="text/javascript">
    function openChild()
    {
      var myChildWin = window.open("child.html", "myChildWin", 'toolbar,width=150,height=100')

    }
  </script>
</head>
<body>
<form>
  <a href="JavaScript:openChild();">search for value</a>
  <br / >
  <input type="text" id="myTextBox" />
</form>
</body>
</html>

Child Page
Code:
<html>
<head>
  <title>JavaScript Sample by tgreer</title>
  <script type="text/javascript">
    function passValue()
    {
      self.opener.document.getElementById("myTextBox").value =
      document.getElementById("mySelect").value;
      self.close();
    }
  </script>
</head>
<body>
  <form>
  <select id="mySelect" onchange="passValue();">
    <option>Tom</option>
    <option>Dick</option>
    <option>Harry</option>
  </select>
  </form>
</body>
</html>

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Here is an example of what everyone's advising. These are .aspx pages so you could use the server processing if needed.

Parent Form
<%@ Page Language="vb" Codebehind="WebForm1.aspx.vb" Inherits="JavaExample.WebForm1"%>

<HTML>
<HEAD>
<script language="javascript">
function NeedMoreInfoWindow(varfn,vartn)
{
var PopUpWindow;
PopUpWindow="popup.aspx?fn="+varfn+"&tn="+vartn
window.open (PopUpWindow,"Noname", 'scrollbars=yes,status=no,width=275,height=220,resizable=yes,top=0')
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<A href="javascript:NeedMoreInfoWindow('Form1','TextBox1');">POPUP</A>
</form>
</A>
</body>
</HTML>


POPUP FORM
<%@ Page Language="vb" Codebehind="PopUp.aspx.vb" Inherits="JavaExample.PopUp"%>
<HTML>
<body onload="CalScript();">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<input type=button onclick="CalScript();" value="ClickMe">
</form>
</body>
<script language="javascript">
function CalScript()
{
if (!(Form1.TextBox1.value==""))
{
window.opener.<%=Request("fn")%>.<%=Request("tn")%>.value=Form1.TextBox1.value
window.close()
}
}
</script>
</HTML>
 
Thanks Tgreer and Stsuing,

I have already done it using the iframes, as i'm using a datagrid to display the select numbers on the parent form.

I'll try it using the way you suggested as well.

Thanks again

 
stuing, at least you and tgreer understood what I was trying to say. Geez, do it on the client...I see stars in your future.
 
Maybe that's why I haven't been back here since April or May. Good luck fly231!
 
Welcome back Veep...[wavey2]


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top