Query String tagged posts

Asp.net Pass Multiple Parameters in Query String or URL

Category: ASP.NET Comments: No comments

If we want to send multiple parameters from one page to another page we need to write code like this

protected void btnSend_Click(object sender, EventArgs e)
{
Response.Redirect(“Default2.aspx?UserId=”+txtUserId.Text+”&UserName=”+txtUserName.Text);
}

 

Now we need to get these values in another page (here I mentioned Default2.aspx) by using QueryStringParameter values with variable names or index values that would be like this
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
lblUserId.Text = Request.QueryString["UserId"];
lblUserName.Text = Request.QueryString["UserName"];
}
}
Or
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
lblUserId.Text = Request.QueryString[0];
lblUserName.Text = Request.QueryString[1];
}
}

 

Read More