HomeLearnGeneral ASP.NET VideosHow Do I: Pass Information From One Page to Another Using a Query String  

[How Do I:] Pass Information From One Page to Another Using a Query String

Please install Silverlight or click download to watch video locally.

In this video Chris Pels will show how information can be passed from one page to another using a query string. First, see how to construct a query string including variable names and values from information on a data entry form. Next, see how to access the query string information when the page is posted including how multiple query string variables are handled. As part of the server side processing of query string information, see how to implement validation for existence of query string variables and if they contain the expected type of data. Finally, learn how to pass special characters including a space and an ampersand in a query string by encoding the string.

Presented by Chris Pels

Duration: 25 minutes, 9 seconds

Date: 26 June 2008

Watch    Video   |   Download    Video   |   VB Code    C# Code

Video downloads: WMV  |  Zune  |  iPod  |  PSP  |  MPEG-4  |  3GP

Audio downloads: AAC  |  WMA  |  MPEG-4  |  MPEG-3  |  MPEG-2

Comments : 31

Leave a Comment

abelanet : On June 26, 2008 7:30 PM said:

Very good video - explained in a very understandable way. Thanks

j.shafee : On June 27, 2008 5:16 AM said:

This is too cool!Thanks Chris Pels!

uwspstar : On June 27, 2008 9:40 AM said:

very nice video

zmb94 : On June 27, 2008 2:43 PM said:

The C# vesion isn't available.

kemalemin : On June 29, 2008 1:44 AM said:

Very basic and irrelevant video! at least it is not something that requires first page publishing on ASP.NET website. Building querystrings is something that every single person who is involved in web programming learns the very first thing.

The video should instead concantrate  

1) Security and Validation of querystrings

2) The limits and limitations of querystrings.

3) When and when not to use querystrings

4) comparison between page.transfer, previouspage. and other methods of retrieving form information and transferring to other target pages.

Nezdet : On July 01, 2008 12:56 PM said:

Nice video Chris!

Iam about to create a serachpage for my project. And Iam about to use querystring to send over searchinformation to the samepage (By samepage I mean, the results will be shown in the searchpage)

Do you recomend us to use the alternative that you showed on the vide

OR

Should we change the Form-tags Method="get"

Which one should you prefer, and why?

(My querystring picks upp all the unnecessary strings if i put the <form method=get>, it get's a bit dirty-querystring)

Hope you can answer this!!

THANKS

rhiana : On July 01, 2008 11:08 PM said:

@kemalemin: Please don't front urself

These are tutorials, it's suppose to be basic...

Nice Video Chris Pels, I've learned a lot from u

DMAsuncion : On July 02, 2008 2:45 AM said:

Thanks a lot, God Bless..

shailatlas : On July 03, 2008 3:31 AM said:

Hello Chris,

Can you please tell me what is the software you use to record the session ?

Thanks

sfrandys : On July 03, 2008 2:55 PM said:

The link that is to be the C# version contains the VB version.  Could this please be changed?  Thanks

chaoslegion05 : On July 10, 2008 10:04 AM said:

The C# link contains the VB code!

tclonyem : On July 10, 2008 11:36 AM said:

Below, I've written the C# code for both code files:

1) Default.aspx.cs

namespace ASPQueryString

{

   public partial class _Default : System.Web.UI.Page

   {

       protected void Page_Load(object sender, EventArgs e)

       {

       }

       protected void btnSubmit_Click(object sender, EventArgs e)

       {

          string targetURL;

          targetURL = "Target1.aspx?";

          targetURL += "CustID=" + Server.UrlEncode(txtCustomerId.Text.Trim());

           targetURL += "&CustName=" + Server.UrlEncode(txtCustomerName.Text.Trim());

           targetURL += "&ProdID=" + Server.UrlEncode(txtProductID.Text.Trim());

           targetURL += "&ProdDesc=" + Server.UrlEncode(txtProductDescription.Text.Trim());

         Response.Redirect(targetURL);

       }

   }

}  

2) Target1.aspx.cs

namespace ASPQueryString

{

   public partial class Target1 : System.Web.UI.Page

   {

     protected void Page_Load(object sender, EventArgs e)

       {

        if ((Request.QueryString["CustID"] != null))

           {

               labCustID.Text = Request.QueryString["CustID"].ToString();

           }

        if ((Request.QueryString["CustName"] != null))

           {

              labCustName.Text = Request.QueryString[1].ToString();

           }

           if ((Request.QueryString["ProdID"] != null))

           {

               labProdID.Text = Request.QueryString["ProdID"].ToString();

           }

           if ((Request.QueryString["ProdDesc"] != null))

           {

               labProdDesc.Text = Request.QueryString[3].ToString();

           }

       }

   }

}  

ngonka2003 : On July 15, 2008 5:13 AM said:

Merci pour cette demonstration tres bien presentée.

asater : On August 22, 2008 6:40 AM said:

Very nice video

Thank you

keep it coming

bsvnhll : On August 28, 2008 6:06 AM said:

this could have been more usefull

cyrussullivan : On September 13, 2008 3:38 PM said:

I am trying to figure out how to bind a query string to a form view item inserted event so that when i hit the insert button i will be taken to a page displaying the inserted data. So far I cant find a tutorial that says how to do that.

anisurrahman : On October 14, 2008 4:56 PM said:

Thank you very much...

agoyal : On October 15, 2008 4:25 AM said:

This is a very helpful video tutorial.

agoyal : On October 15, 2008 4:25 AM said:

This is a very helpful video tutorial.

ccgilson : On November 07, 2008 8:13 AM said:

Very clear and helpful, but for me the video wastes too much time with setting up. The tutorial's title is: 'How Do I: Pass Information From One Page to Another Using a Query String' and not 'How Do I: Place basic controls into an HTML page, name them, position them and then pass Information From One Page to Another Using a Query String'

djafer : On November 12, 2008 8:14 AM said:

thanx

djibril_chimere_DIAW : On November 30, 2008 12:13 PM said:

Thanks! Jërëjëf !

Hamza_zarar : On December 01, 2008 4:24 AM said:

very nice video :)

mdmk : On January 22, 2009 7:44 AM said:

Its Really wonderfull!!

bohunt : On February 13, 2009 5:36 PM said:

Nice video.

Nilesh810 : On March 10, 2009 7:35 AM said:

I have two tables pre_enquiry & enquiry ,enquiryno is primary key of pre_enquiry table,username is also stored in it.In enquiry webform if i enter username then related enquiryno. should be autofilled in textbox ,& delete the record from pre_enquiry table

I have done following

public partial class EnquiryForm : System.Web.UI.Page

{

SqlConnection cn,cn1;

SqlCommand cmd;

//DataTable dt;

protected void Page_Load(object sender, EventArgs e)

{

// if (!IsPostBack)

//{

// cn = new SqlConnection(ConfigurationManager.ConnectionStrings["BruserConnectionString2"].ConnectionString);

// cmd = new SqlCommand("select EnquiryNo from Pre_Enquiry where(Uname=" + TextBox1.Text + ")");

// cn.Open();

// tr=cmd.ExecuteReader();

// while (tr.Read)

// {

// int i = tr["EnquiryNo"];

//}

// tr.Close();

//cn.Close();

//}

}

protected void Button2_Click(object sender, EventArgs e)

{

// cn = new SqlConnection(ConfigurationManager.ConnectionStrings["BruserConnectionString2"].ConnectionString);

// TxtEnqNo.Text = Convert.ToString(cmd = new SqlCommand("select EnquiryNo from Pre_Enquiry Where(Uname=" + TextBox1.Text + ");", cn));

// //TxtEnqNo.Text = Convert.ToString("EnquiryNo");

// cn.Open();

// cmd.ExecuteNonQuery();

// cn.Close();

}

protected void Button1_Click(object sender, EventArgs e)

{

cn = new SqlConnection(ConfigurationManager.ConnectionStrings["BruserConnectionString2"].ConnectionString);

//cmd = new SqlCommand("select EnquiryNo.,enqDate,Uname,BranhName,TelNo from Pre_Enquiry");

//cmd = new SqlCommand("Insert into enquiry values('" + DropDownList1.SelectedItem.Text + "','" + DropDownList2.SelectedItem.Text + "','" + TxtEnqNo.Text="select EnquiryNo from Pre_Enquiry where (Uname="+TextBox1.Text+")" + "','" + DropDownList3.SelectedItem.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + Convert.ToInt32(TextBox3.Text) + "','" + Convert.ToInt32(TextBox4.Text) + "','" + Convert.ToInt32(TextBox5.Text) + "','" + DropDownList4.SelectedItem.Text + "/" + DropDownList6.SelectedItem.Text + "/" + DropDownList7.SelectedItem.Text + "','" + DropDownList5.SelectedItem.Text + "','" + TextBox6.Text + "','" + TextBox8.Text + "','" + RadioButtonList2.SelectedItem.Text + "','" + TextBox9.Text + "','" + RadioButtonList3.SelectedItem.Text + "','" + RadioButtonList4.SelectedItem.Text + "','" + RadioButtonList5.SelectedItem.Text + "','" + TextBox7.Text + "');", cn);

cmd = new SqlCommand("Insert into enquiry values('" + DropDownList1.SelectedItem.Text + "','" + DropDownList2.SelectedItem.Text + "','" + TxtEnqNo.Text + "','" + DropDownList3.SelectedItem.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + Convert.ToInt32(TextBox3.Text) + "','" + Convert.ToInt32(TextBox4.Text) + "','" + Convert.ToInt32(TextBox5.Text) + "','" + DropDownList4.SelectedItem.Text + "/" + DropDownList6.SelectedItem.Text + "/" + DropDownList7.SelectedItem.Text + "','" + DropDownList5.SelectedItem.Text + "','" + TextBox6.Text + "','" + TextBox8.Text + "','" + RadioButtonList2.SelectedItem.Text + "','" + TextBox9.Text + "','" + RadioButtonList3.SelectedItem.Text + "','" + RadioButtonList4.SelectedItem.Text + "','" + RadioButtonList5.SelectedItem.Text + "','" + TextBox7.Text + "');", cn);

cn.Open();

cmd.ExecuteNonQuery();

cn.Close();

}

protected void TextBox1_TextChanged(object sender, EventArgs e)

{

//dt=new DataTable("Pre_Enquiry");

//tr = new DataTableReader(dt);

// cmd=new SqlCommand("select EnquiryNo from Pre_Enquiry where(Uname="+TextBox1.Text+")");

int i;

cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["BruserConnectionString2"].ConnectionString);

cmd = new SqlCommand("select EnquiryNo from Pre_Enquiry where(Uname=@uname);", cn1);

cn1.Open();

SqlDataReader tr;

tr=cmd.ExecuteReader();

while (tr.Read())

{

i = Convert.ToInt32(tr["EnquiryNo"]);

TxtEnqNo.Text = Convert.ToString(i);

//TxtEnqNo.Text=cmd.Parameters.Add("@EnquiryNo").Value;

}

tr.Close();

cn1.Close();

}

}

abhinandanbansal : On April 05, 2009 2:58 PM said:

Good video...

Mike Vytal : On April 08, 2009 11:45 AM said:

EXCELLENT VIDEO CHRIS! I can't wait to get to work today! THANK YOU VERY MUCH!

mobileiq : On July 03, 2009 7:29 PM said:

Video is a bit long for the amount of content. Next time consider demoing with fewer fields (2 instead of 4 would have done the job just as well) and using design view instead of source view (faster to demo and easier to understand for novice users).

benives@gmail.com : On July 08, 2009 9:19 PM said:

Nice. I would like to see more videos in C# instead of VB. I also agree with the previous comment that many of these videos would work better in design view, at least when adding components. I don't see any value in watching somebody type in a text box or button control.

zibrohimov : On November 16, 2009 8:21 AM said:

Good for beginners. But, when I was watching the video i got bored. He explained common things too much and took the time.

But, thanks for such a good bunch of video tutorials.

Leave a Comment

You must be logged in to leave a comment. Click here to log in.

Microsoft Communities