AndyPandy
asked on
How to preserve textbox.text after a redirect?
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!
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>
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
ASKER
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.
This doesn't have to work between differant sessions, just when flipping back and forth in this origianl session.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Chapmanjw,
I get the effect I wanted (saving the value in textbox1.text)when I use this:
protected void HyperLink1_PreRender(objec t 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) ;
}
I get the effect I wanted (saving the value in textbox1.text)when I use this:
protected void HyperLink1_PreRender(objec
{
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)
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.