21 June 2013

Asp.net Pass Multiple Parameters in Query String or URL

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];
}
}

No comments:

Post a Comment