Querystring

G

Guest

hi,

i want to have a querystring in a webpage. i dont mind what it does (i just
want to experiment with it). how do i get the asp.net page to do something
when i type in a querystring? if you dont undertsand the question, dont
hesitate to ask.

thanks in advance
--
Look Out!

Helter Skelter
Yellow Submarine
Pepperland

PS. Get Back!
 
T

Teemu Keiski

Hi,

if you request a page say with

mypage.aspx?id=1

You can get the value of the id in querystring with
Request.QueryString("id")

For example

Dim intId As Integer=CInt(Request.QueryString("id"))

After that you could use the intID to do what you need to do with it.
 
S

sloan

You usually deal with a QueryString value in the Page_Load Event.


www.mysite.com/myfile.aspx?param=123

When you fire up this page, the myfile.aspx code will fire. myfile.aspx.cs
(or .vb) has a Page_Load event.

Here is how you handle it.

string uuid = string.Empty;
if (null!= Context.Request.QueryString["param"])
{
uuid = (string)Context.Request.QueryString["param"];
}

Then...you do something with the (string) uuid, if it exists. Like ... call
a business object to get info about a customer or something like that.

To say it another way.

when you call
www.mysite.com/myfile.aspx?param=123
then
uuid will equal "123"

when you call
www.mysite.com/myfile.aspx
then uuid will (remain) an empty string (string.Empty)
 
G

Guest

dear sloan,

thanks for the advice. my Page_Load event, however, says this:

protected void Page_Load(object sender, EventArgs e)
{
string uuid = string.Empty;
if (null != Context.Request.QueryString["help"])
{
uuid = (string)Context.Request.QueryString["help"];
}
if (uuid = "contact")
{
Page.Title = "cheese";
}
}

and it doesnt work. the title should change to cheese when the help
querystring parameter is contact but there is a compilation error
--
Look Out!

Helter Skelter
Yellow Submarine
Pepperland

PS. Get Back!


sloan said:
You usually deal with a QueryString value in the Page_Load Event.


www.mysite.com/myfile.aspx?param=123

When you fire up this page, the myfile.aspx code will fire. myfile.aspx.cs
(or .vb) has a Page_Load event.

Here is how you handle it.

string uuid = string.Empty;
if (null!= Context.Request.QueryString["param"])
{
uuid = (string)Context.Request.QueryString["param"];
}

Then...you do something with the (string) uuid, if it exists. Like ... call
a business object to get info about a customer or something like that.

To say it another way.

when you call
www.mysite.com/myfile.aspx?param=123
then
uuid will equal "123"

when you call
www.mysite.com/myfile.aspx
then uuid will (remain) an empty string (string.Empty)







Helter Skelter said:
hi,

i want to have a querystring in a webpage. i dont mind what it does (i just
want to experiment with it). how do i get the asp.net page to do something
when i type in a querystring? if you dont undertsand the question, dont
hesitate to ask.

thanks in advance
--
Look Out!

Helter Skelter
Yellow Submarine
Pepperland

PS. Get Back!
 
S

sloan

Are you debugging it? To sse if it exists.

Remember, it will only work if you load a page that looks like this:

mypage.aspx?help=contact

Also, I usually convert ToUpper() when doing string compares: aka, Contact
is not the same as contact

Change

if(uuid.ToUpper() == "CONTACT") //that's 2 (TWO) equal signs
{

}

PPS
You need the DOUBLE EQUALS sign in c#. when comparing values.



Helter Skelter said:
dear sloan,

thanks for the advice. my Page_Load event, however, says this:

protected void Page_Load(object sender, EventArgs e)
{
string uuid = string.Empty;
if (null != Context.Request.QueryString["help"])
{
uuid = (string)Context.Request.QueryString["help"];
}
if (uuid = "contact")
{
Page.Title = "cheese";
}
}

and it doesnt work. the title should change to cheese when the help
querystring parameter is contact but there is a compilation error
--
Look Out!

Helter Skelter
Yellow Submarine
Pepperland

PS. Get Back!


sloan said:
You usually deal with a QueryString value in the Page_Load Event.


www.mysite.com/myfile.aspx?param=123

When you fire up this page, the myfile.aspx code will fire. myfile.aspx.cs
(or .vb) has a Page_Load event.

Here is how you handle it.

string uuid = string.Empty;
if (null!= Context.Request.QueryString["param"])
{
uuid = (string)Context.Request.QueryString["param"];
}

Then...you do something with the (string) uuid, if it exists. Like ... call
a business object to get info about a customer or something like that.

To say it another way.

when you call
www.mysite.com/myfile.aspx?param=123
then
uuid will equal "123"

when you call
www.mysite.com/myfile.aspx
then uuid will (remain) an empty string (string.Empty)







hi,

i want to have a querystring in a webpage. i dont mind what it does (i just
want to experiment with it). how do i get the asp.net page to do something
when i type in a querystring? if you dont undertsand the question, dont
hesitate to ask.

thanks in advance
--
Look Out!

Helter Skelter
Yellow Submarine
Pepperland

PS. Get Back!
 
H

Hans Kesting

dear sloan,
thanks for the advice. my Page_Load event, however, says this:

protected void Page_Load(object sender, EventArgs e)
{
string uuid = string.Empty;
if (null != Context.Request.QueryString["help"])
{
uuid = (string)Context.Request.QueryString["help"];
}
if (uuid = "contact")
{
Page.Title = "cheese";
}
}

and it doesnt work. the title should change to cheese when the help
querystring parameter is contact but there is a compilation error

Is the compilation error on the Page.Title line? I don't think it's
possible to set the title of the html page this way!
(By the way: if you receive errors, it will help us help you if you
specify what error it is exactly - exact message text, point out the
line where it occurs, etc)

Or is it on the 'uuid = "contact" ' line? To compare values, you need
to use ==. A single = is used *only* in an assignment.


One way to set the title:

in the aspx:
<html>
<head>
<title><asp:Literal id="litTitle" runat="server" /></title>
....


in the codebehind (I'm assuming 1.1) declare
protected Literal litTitle

and then set
litTitle.Text = "cheese";


Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Feedback form 1
create a Popup 2
Image Based Website 2
SmtpException with email form 4
Age gate code 0
Querystring validation 8
Accessing URL encoded querystring vars 4
DATA THROUGH QUERYSTRING 4

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top