narasiman rao

narasiman rao

  • NA
  • 519
  • 767.6k

how to pass values to another page using query string

Aug 27 2012 6:45 AM

in design i have  two pages.

in first design page i have two textboxes

Number1  10(textbox1)
Number2  12(textbox2)


first design page code as follows

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string number1   = Request.QueryString[0];
        string number2 = Request.QueryString[1];

        int result = Convert.ToInt32(number1) + Convert.ToInt32(number2);
        //TextBox1.Text = result.ToString();
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string urltoNaviget = " ~/Add.aspx?Number1=" + txt_name.Text + "&Number2=" + txt_age.Text;
        LinkButton1.PostBackUrl = urltoNaviget;
    }
}


In Second design  page i have one textbox

Adding Two numbers    22(textbox1)


Second  design page code as follows

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string number1 = Request.QueryString[0];
        string number2 = Request.QueryString[1];
        // The other way to Read the values 
        //string number1 = Request.QueryString["Number1"];
        //string number2 = Request.QueryString["Number2"];
        int result = Convert.ToInt32(number1) + Convert.ToInt32(number2);
        TextBox1.Text = result.ToString();
    }
}


When i run i have following error as follows

Index was out of range. Must be non-negative and less than the size of the collections.
Parameter name: index 


Please help me

thanks,
Rao.,

Answers (1)