Pass Label Value from one Page to another in ASP.Net

Last Reply on Mar 05, 2014 02:24 AM By Azim

Posted on Mar 05, 2014 02:01 AM

I am trying to redirect to PageOne, with a URL string of status=true or false, which is based on this.Label4.Text = this.Request.QueryString[CustomerStatus"]; And this label is what the customer "chooses." The only thing is that status is null right when I get into the onclick event listener for this redirect. How do I pass a variable in a response redirect without it becoming null, when this variable comes from the previous page, or response redirect from the previous page. Using static variables and such have proven difficult as they are not working either. Can you please provide a code example of how to do this? Thank you.

You are viewing reply posted by: Azim on Mar 05, 2014 02:24 AM.
Posted on Mar 05, 2014 02:24 AM Modified on on Mar 05, 2014 02:34 AM

You are receiving the Customer Status from previous page then you are passing it again to next page. I would like to suggest you to use Session for this.

For your QueryString:

You need to check your QueryString whether it having some value or not:

private string Name
    {
        get
        {
            return Server.UrlDecode(Request.QueryString["Name"]);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.lblName.Text = this.Name;
        }
    }

This way you can pass value in Response.Redirect.

C#:

protected void PassValue(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("~/Page2.aspx?Name={0}", this.lblName.Text));
    }

 Thank You.