How to preserve textbox.text after a redirect?

Posted on 2010-09-13
Medium Priority
Last Modified: 2012-08-13
My textbox.text dissappears after a redirect.
How can can I preserve the textbox.text value?
For example:
I type in "bananas"
Then I press the button ,  for a redirect to Google "bananas"
When I am done with the Google page I go back to my page,
but "bananas" is gone!
I want "bananas" in the textbox.text!
I want my bananas!
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void googButton1_Click(object sender, ImageClickEventArgs e)
        string gogetit = "http://www.google.com/search?source=ig&hl=en&q=" + TextBox1.Text;
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<body >
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server" 
    <asp:ImageButton ID="googButton1" runat="server"  AlternateText="Google" 
        OnClick="googButton1_Click" />

Open in new window

Question by:AndyPandy
  • 2
  • 2
LVL 21

Expert Comment

ID: 33667323
You could set a cookie with the value and have the page_load check for the cookie each time you load the page:  http://www.codetoad.com/asp.net/cookies.asp

Author Comment

ID: 33667474
I was hoping to save it in a variable (or better yet in the orginal textbox.text)
This doesn't have to work between differant sessions, just when flipping back and forth in this origianl session.
LVL 21

Assisted Solution

chapmanjw earned 800 total points
ID: 33667784
The problem lies in that you are going to a different website entirely that is not under your control.  You have to use a cookie or session variable to persist data.

Author Comment

ID: 33668220
Hi Chapmanjw,
I get the effect I wanted (saving the value in textbox1.text)when I use this:
  protected void HyperLink1_PreRender(object sender, EventArgs e)
        HyperLink1.NavigateUrl = "http://www.google.com/search?source=ig&hl=en&q=" + TextBox1.Text;

Why is this differant than the following? (as far as saving the value in textbox1.text?):

  protected void googButton1_Click(object sender, ImageClickEventArgs e)
        string gogetit = "http://www.google.com/search?source=ig&hl=en&q=" + TextBox1.Text;


Accepted Solution

Syfhix earned 1200 total points
ID: 33679755
easiest way. Save it in a session. if the session variable is nothing it shows nothing, if it contains a value it will show the value.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

586 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question