Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

Querystring

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Helter Skelter - 15 Feb 2006 19:26 GMT
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
Signature

Look Out!

Helter Skelter
Yellow Submarine
Pepperland

PS. Get Back!

Teemu Keiski - 15 Feb 2006 19:34 GMT
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.

Signature

Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

> hi,
>
[quoted text clipped - 5 lines]
>
> thanks in advance
sloan - 15 Feb 2006 19:38 GMT
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,
>
[quoted text clipped - 4 lines]
>
> thanks in advance
Helter Skelter - 15 Feb 2006 21:19 GMT
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
Signature

Look Out!

Helter Skelter
Yellow Submarine
Pepperland

PS. Get Back!

> You usually deal with a QueryString value in the Page_Load Event.
>
[quoted text clipped - 34 lines]
> >
> > thanks in advance
sloan - 16 Feb 2006 01:26 GMT
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.

> dear sloan,
>
[quoted text clipped - 54 lines]
> > >
> > > thanks in advance
Hans Kesting - 16 Feb 2006 12:28 GMT
> dear sloan,
>
[quoted text clipped - 15 lines]
> 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
Steve C. Orr - 15 Feb 2006 20:37 GMT
To get a value from the querystring you'd use code something like this:
Dim s as string = Request.QueryString("MyValue").ToString()

Here are more details:
http://SteveOrr.net/faq/PassValues.aspx

Signature

I hope this helps,
Steve C. Orr
MCSD, MVP
http://SteveOrr.net

> hi,
>
[quoted text clipped - 4 lines]
>
> thanks in advance

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.