473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

TextBox1.Text = Request.QueryString in Page_Load - ASP.NET C#

I'm using CSharp/ASP.NET 2.0 and trying to create a simple search page that records the user query in the URL (so can be bookmark) and also re-writes the query int the original TextBox. This only works once; there after the old query gets re-written to the TextBox regardless of what is entered.

I think this is because I'm using the Page_Load event which may being fired, replacing the new query with the one in the current URL, between time I enter new Text and click button ... but not sure how else to do it.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <!-- the search form -->
  3. <form id="form1" runat="server">
  4. <div>
  5. <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
  6. <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
  7. <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  8. </div>
  9. </form>
  10.  
Expand|Select|Wrap|Line Numbers
  1. /* event to re-load the page with the query terms in the URL
  2.  * but only works the first time when there is no value in the
  3.  * URL
  4.  */
  5. protected void Button1_Click(object sender, EventArgs e)
  6. {
  7. Response.Redirect("Default.aspx?q=" + TextBox1.Text, true);
  8. }
  9.  

Expand|Select|Wrap|Line Numbers
  1. // write the q value from URL to search box
  2. protected void Page_Load(object sender, EventArgs e)
  3. {
  4.   if (Request.QueryString["q"] != null)
  5.   {
  6.     TextBox1.Text = Request.QueryString["q"];
  7.   }
  8. }
  9.  
Advice?

Thanks!

Rick
Feb 13 '08 #1
0 14226

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tom Youngquist | last post by:
I am trying to download a text file that my .NET page has just created based on entered parameters on the web page. Everything seems to work and the file is created. I am using the following code...
4
by: Steve | last post by:
Hi All, This problem is really annoying me, as I am sure there is a simple solution to it. If I try to read a querystring value in the Page_Load event and that querystring does not exist I...
3
by: malcolm | last post by:
Inside of a Page class, how do I capture the Request object values before the Page_Load event is called of that Page? I have a situation where I have many server controls on a Page that get...
1
by: franklinbruce | last post by:
Hi all, I am passing a value from Javascript to a IFrame. when i tired to acces that value like request.querystring("id1") it says "name id1 is not declared" code as follow: ---------------...
4
by: Tim::.. | last post by:
Can someone please tell me why this doesn't work! Error: Request is not available in this context Private rowID As Integer = Request.QueryString(ID) I need to have the variable rowID...
19
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred...
3
by: james | last post by:
Hey Guys, Do you have any idea how to acces Request.QueryString in a MasterPage? I need to use it to modify my sitemap. My code is: public partial class MasterPage :...
3
by: Sharon | last post by:
hello all, I was successfull in passing one value from first webpage to second webpage, but not sure how to pass three textbox values from the first page to the second page. Below is the code i...
4
by: =?Utf-8?B?UGF1bA==?= | last post by:
This may be a stupid question but... How do I programmtically access the page's request.querystring value in a custom user control. I tried doing this in the page_load routine of the user...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.