?
Solved

How to preserve textbox.text after a redirect?

Posted on 2010-09-13
5
Medium Priority
?
427 Views
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;
        Response.Redirect(gogetit);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   
<title></title>
</head>
<body >
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server" 
         BorderStyle="Solid"></asp:TextBox>
    <asp:ImageButton ID="googButton1" runat="server"  AlternateText="Google" 
        OnClick="googButton1_Click" />
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:AndyPandy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:chapmanjw
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
0
 

Author Comment

by:AndyPandy
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.
 
0
 
LVL 21

Assisted Solution

by:chapmanjw
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.
0
 

Author Comment

by:AndyPandy
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;
       Response.Redirect(gogetit);
     }

0
 
LVL 1

Accepted Solution

by:
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.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

800 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