0

Hello everyone,
Could someone please give me a good explanation about what I can do with it? I can't really find it on Google..
Thanks in advance,
Davey

5
Contributors
17
Replies
18
Views
7 Years
Discussion Span
Last Post by sknake
Featured Replies
  • I use querystring to retrieve parameters send from another form, let's say that you are and index.html and there is a link url to default.aspx like this ~/Default.aspx?var=hello then and the Server code from Default.aspx to retrieve that value i have this. [code=csharp] string stTest = Request.QueryString["var"]; [/code] now stTest … Read More

  • 1
    sknake 1,622   7 Years Ago

    Its handy if you want to pass data to other pages, especially when you want it retained in the browser's history. If you POST search terms to google for example then you wouldn't have a list of all searches you performed in your browser history. Read More

  • 1
    sknake 1,622   7 Years Ago

    Explain what you are trying to do first. >>. At this point I get the entire code of my page! Not good, anyone got an idea about what's wrong? Here is my code: From what you said I was guessing that when you entered a query string you didn't want … Read More

2

I use querystring to retrieve parameters send from another form, let's say that you are and index.html and there is a link url to default.aspx like this
~/Default.aspx?var=hello

then and the Server code from Default.aspx to retrieve that value i have this.

string stTest = Request.QueryString["var"];

now stTest is equal to "hello"
hope that help you

Votes + Comments
if sknake thinks it is worth it, it is worth it
good explanation
1

Its handy if you want to pass data to other pages, especially when you want it retained in the browser's history. If you POST search terms to google for example then you wouldn't have a list of all searches you performed in your browser history.

Votes + Comments
repute back function
0

It comes from the days of ASP.

The "Request.QueryString" command is used to collect values in a form with method="get".

SimpleForm_1.asp

<form method="get" action="SimpleFormHandler_1.asp">
    <TEXTAREA NAME="location" COLS=33 ROWS=4></TEXTAREA>
    <input type='submit' value='Add Event'>
</form>

SimpleFormHandler_1.asp

<%@ Language=VBScript %>

<%
        Dim userLocation

        'location is the variable name as defined by "NAME="
        'in SimpleForm_1.asp
        userLocation = Request.QueryString("location")
%>

The "Request.Form" command is used to collect values in a form with method="post".

SimpleForm_2.asp

<form method="post" action="SimpleFormHandler_2.asp">
    <TEXTAREA NAME="location" COLS=33 ROWS=4></TEXTAREA>
    <input type='submit' value='Add Event'>
</form>

SimpleFormHandler_2.asp

<%@ Language=VBScript %>

<%
        Dim userLocation

        'location is the variable name as defined by "NAME="
        'in SimpleForm_2.asp
        userLocation = Request.form("location")
%>

See http://www.w3schools.com/ASP/asp_inputforms.asp

0

You'll probably find more info on it if you search for "ASP Request.QueryString" and "ASP Request.Form".

C#

string userLocation;
userLocation = Request.QueryString["location"];

C#

string userLocation;
userLocation = Request.Form["location"];
0

Ok, I will flag this thread then.
Ok, so I read all of your comments, and thanks for it :)
I'm gonna ask another question about this.

I need to get the id=123 in http://www.website.com/something.php?id=123, in my C# application. Whenever I press a new button on the website the C# app needs to get the new id, or
value etc etc. So would this then be the best solution to get it? Or could I better use something else..?

Thanks again,
Davey

0

I flagged it for you. The button should be located under the reply:

sknake Online
Posting Virtuoso
Re: QueryString #9 1 Minute Ago | Add to sknake's Reputation | Flag Bad Post

0

Ok, so I got a bit of a solution at this point, I got the PHP page sending the QueryString to another PHP page, which sends it to my C# app, at least.. its suppose to do that. At this point I get the entire code of my page! Not good, anyone got an idea about what's wrong? Here is my code:

PHP to get the QueryString (There is more, but this is the only bit that matters)

<?
require('sendtoC.php');
$send = new sendtoC();

if($_GET['input'] == "")
{
    echo "Variabele is leeg.";
}
else
{
	$var = $_GET['input'];
    $send->write($var);
}
?>

PHP code to receive the QueryString, and send it to C# app

<?
class sendtoC {
function write($var) {
	print($var); 
	}
}
?>

the C# app

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Web;
using System.IO;

namespace MVC_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public string ConnectWeb()
        {
            string website = @"http://www.daveybrouwer.eu/test.php";
            WebRequest request = WebRequest.Create(website);
            WebResponse response = request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string query = reader.ReadLine();
            return query;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = ConnectWeb();
        }
    }
}

Your help is greatly appreciated,
Davey

0

Do you not want to get the entire page?

namespace daniweb.web
{
  public partial class Cb : System.Web.UI.Page
  {
    protected override void OnInit(EventArgs e)
    {
      base.OnInit(e);
      if (Request.QueryString["parm"] != null)
      {
        Response.Write("You entered the value: " + Request.QueryString["parm"]);
        Response.Flush();
        Response.Close();
      }
    }

URL:
http://localhost:14332/Cb.aspx?parm=hello

Result:

You entered the value: hello
0

Do you not want to get the entire page?

namespace daniweb.web
{
  public partial class Cb : System.Web.UI.Page
  {
    protected override void OnInit(EventArgs e)
    {
      base.OnInit(e);
      if (Request.QueryString["parm"] != null)
      {
        Response.Write("You entered the value: " + Request.QueryString["parm"]);
        Response.Flush();
        Response.Close();
      }
    }

URL:
http://localhost:14332/Cb.aspx?parm=hello

Result:

You entered the value: hello

Could you give me some explanation about this? I dont really get it.. sorry :(

1

Explain what you are trying to do first.

>>. At this point I get the entire code of my page! Not good, anyone got an idea about what's wrong? Here is my code:

From what you said I was guessing that when you entered a query string you didn't want to render the page, but rather wanted to only render something custom. Please clarify what you are trying to do

0

Ok,

well when the index page is loaded and I press on a button on that page, I want to send the link of that button (well the QueryString) to my C# application. So that my C# can see what the QueryString is, and then save something to a database, or render a new page etc. etc. I am trying to make it along the MVC pattern, this is how I understood MVC works.. If something isn't clear please ask.

Regards again,
Davey :)

0

I can't get this to work in my C# application or in my PHP page.. What am I doing wrong?

0

I have no idea what you're doing -- so I don't know what you're doing wrong.

Explain what you are trying to do first.

>>. At this point I get the entire code of my page! Not good, anyone got an idea about what's wrong? Here is my code:

From what you said I was guessing that when you entered a query string you didn't want to render the page, but rather wanted to only render something custom. Please clarify what you are trying to do

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.