Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code behind page

C#
protected void login_Click(object sender, EventArgs e)
  {
      Response.Redirect("Default2.aspx?user_name=" + TextBox1.Text + "");
  }



C#
protected void Page_Load(object sender, EventArgs e)
{
   //TextBox1.Text = Request.QueryString["username"];
    if (Request.QueryString["user_name"] == null)
    {
        Label1.Text = "querystring not found";
    }
    else
    {
        Label1.Text = Request.QueryString["username"].ToString();//here is null refrence exception
    }
}
Posted
Updated 9-Sep-12 22:50pm
v2

Your query string names are different :-

your code should be like this:-

Label1.Text = Request.QueryString["user_name"].ToString();//here is null re

instead of this one what u have used in your code :-
Label1.Text = Request.QueryString["username"].ToString();//here is null refrence

so use 1st one. ( Request.QueryString["user_name"].ToString() )
 
Share this answer
 
Comments
Rashid Choudhary 10-Sep-12 4:58am    
thanxxx sir
Sunil Kumar Pandab 10-Sep-12 5:04am    
most welcome dear
Sunil Kumar Pandab 10-Sep-12 5:06am    
I gave you solution and you down voted my answer
Rashid Choudhary 10-Sep-12 7:02am    
okkkkkkkkk
Try this,

C#
protected void login_Click(object sender, EventArgs e)
  {
      Response.Redirect("Default2.aspx?user_name=" + TextBox1.Text + "",false);
  }
 
Share this answer
 
Try this:
1st Page:
C#
protected void login_Click(object sender, EventArgs e)
{
      Response.Redirect("Default2.aspx?user_name='" + TextBox1.Text + "'");
}

2nd Page:
C#
protected void Page_Load(object sender, EventArgs e)
{
   //TextBox1.Text = Request.QueryString["username"];
    if (Request.QueryString["user_name"] == null)
    {
        Label1.Text = "querystring not found";
    }
    else
    {
        Label1.Text = Request.QueryString["user_name"].ToString();//_ was missing
    }
}



--Amit
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900