ASP.NET Server controls on cross post back

Discussion in 'Software' started by Fachmann, Oct 31, 2007.

  1. Fachmann

    Fachmann

    Joined:
    Oct 31, 2007
    Messages:
    1
    Likes Received:
    0
    Hi
    Why don’t their values preserve on cross post back?
    For example in the following code:
    // Default.aspx

    public partial class _Default : System.Web.UI.Page

    {

    protected void Page_Load(object sender, EventArgs e)

    {
    }

    protected void Button1_Click(object sender, EventArgs e)

    {
    HiddenField1.Value = "HiddenField1 value";
    Label1.Text = "Label1 Text";
    }

    }

    //Default2.aspx

    public partial class Default2 : System.Web.UI.Page

    {
    protected void Page_Load(object sender, EventArgs e)

    {
    Label1.Text = Request.Form["HiddenField1"];
    Label2.Text = Request.Form["Label1"];
    }

    }

    The values of Label1 and Label2 are "".
    Why is this happening? Is this a bug and could be fixed somehow?

    Thanks.
     
    Fachmann, Oct 31, 2007
    #1
    1. Advertisements

  2. Fachmann

    fred5152

    Joined:
    Dec 18, 2007
    Messages:
    12
    Likes Received:
    0
    Use
    If(!IsPostBack)
    I think it might solve your Problem
     
    fred5152, Dec 18, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.