473,403 Members | 2,183 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,403 software developers and data experts.

Extracting the query parameters

I have a button named Button1, and I wrote an event handler for the
OnClick event.

protected void Button1_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("Default.aspx?q=" + this.TextBox1.Text+ " ");
}

The TextBox1 is a text box that takes user input.
I get the text box content by extracting the query parameters as
follows:

protected string Q
{
get
{
string query = this.Request.Params["q"];
if (query == String.Empty)
return null;
return query;
}
}

The Page_Load event handler is as follows:

protected void Page_Load(object sender, System.EventArgs e)
{
// Press Button1 on enter
Page.RegisterHiddenField("__EVENTTARGET", "Button1");
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
if (!IsPostBack)
{
if (this.Q != null)
{
// I call my own method
findResults();
}
DataBind();
}
}

The problem is if I enter the term "c# language", the value of the
TextBox1.Text is "c# language" which is as I expect. But as soon as the
response is redirected and the control goes to the Page_Load(), then
"this.Q" value is being set to "c".
How do I send the correct value?
Thanks in advance.

Jan 22 '07 #1
6 1666
HtmlEncode it as Server.HtmlEncode(this.TextBox1.Text) and HtmlDecode on the
other end.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"sunil" <sa**********@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
>I have a button named Button1, and I wrote an event handler for the
OnClick event.

protected void Button1_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("Default.aspx?q=" + this.TextBox1.Text+ " ");
}

The TextBox1 is a text box that takes user input.
I get the text box content by extracting the query parameters as
follows:

protected string Q
{
get
{
string query = this.Request.Params["q"];
if (query == String.Empty)
return null;
return query;
}
}

The Page_Load event handler is as follows:

protected void Page_Load(object sender, System.EventArgs e)
{
// Press Button1 on enter
Page.RegisterHiddenField("__EVENTTARGET", "Button1");
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
if (!IsPostBack)
{
if (this.Q != null)
{
// I call my own method
findResults();
}
DataBind();
}
}

The problem is if I enter the term "c# language", the value of the
TextBox1.Text is "c# language" which is as I expect. But as soon as the
response is redirected and the control goes to the Page_Load(), then
"this.Q" value is being set to "c".
How do I send the correct value?
Thanks in advance.

Jan 22 '07 #2

Eliyahu Goldin wrote:
HtmlEncode it as Server.HtmlEncode(this.TextBox1.Text) and HtmlDecode on the
other end.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
Hi Eliyahu,
I have tried out as you have suggested. Now the line looks like
protected void Button1_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("Default.aspx?q=" +
Server.HtmlEncode(this.TextBoxQuery.Text));
}

The new Q property looks like:

protected string Q
{
get
{
string query = Server.HtmlDecode(this.Request.Params["q"]);
if (query == String.Empty)
return null;
return query;
}
}

But this didnt work out for me. Still, the value of query is "c"
Am I doing correct?

Jan 22 '07 #3
"sunil" <sa**********@gmail.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
Am I doing correct?
Try URLEncode / URLDecode instead of HTMLEncode / HTMLDecode
Jan 22 '07 #4

Mark Rae wrote:
"sunil" <sa**********@gmail.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
Am I doing correct?

Try URLEncode / URLDecode instead of HTMLEncode / HTMLDecode
Hi Mark,
Thanks for the reply. Using UrlEncode/UrlDecode almost worked out. It
is working for the first example that I had given("c# language")
But if I give:"c++ language" in the TextBox, then after decoding it is
changed to "c language".
How can I avoid this?

Jan 22 '07 #5
Use:

UrlPathEncode

UrlEncode has some problem while dealing with spaces, '+';

-Akki
sunil wrote:
Mark Rae wrote:
"sunil" <sa**********@gmail.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
Am I doing correct?
Try URLEncode / URLDecode instead of HTMLEncode / HTMLDecode

Hi Mark,
Thanks for the reply. Using UrlEncode/UrlDecode almost worked out. It
is working for the first example that I had given("c# language")
But if I give:"c++ language" in the TextBox, then after decoding it is
changed to "c language".
How can I avoid this?
Jan 23 '07 #6
Hi
I have used UrlEncode only to encode the string? On the receiver side,
I am not decoding.
The problem for the previous example of "c++ language being converted
to "c language" is that I was decoding the received query string using
UrlDecode. So the decoding happens twice.
Now I am not decoding on the receiver side, it works perfectly

Jan 23 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Astra | last post by:
Hi All Is there an ASP way of extracting the height and width of a swf file so that I can specify these dims when adding the whole OBJECT code to the web page? Thanks Robbie
3
by: Ryan Hubbard | last post by:
I would like to run a query from VBA. The query will be one with parameters. Is there a way to run the query and have Access prompt for the values like it does if I where to execute it through...
5
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
3
by: Alfred | last post by:
Hi I would like to extract only 15 records at a time from the backend in alfabetic order. Click on a button and then the next 15. Reason data must come over a 56k modem. The data is not...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
2
by: Robert McEuen | last post by:
Sorry if this double-posts...Google doesn't do a very good job of communicating whether something has posted or not. Using Access 97, WindowsXP Is there a way to pass command line parameters...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
1
by: Phat G5 (G3) | last post by:
I found this little script for extracting parameters from a url but wondered what the shortest and most efficient way to do it would be, like the following or via regexp? function...
4
by: apatel85 | last post by:
Hey Guys, Total Number of Records (Based on 5 fields): 1000 Total Unique Records (Based on 5 Fields): 990 Total number of fields: 5 I have question regarding extracting duplicates from the...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.