Click here to Skip to main content
12,629,978 members (31,727 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi..
I'm developing one Asp.net application with c#.
Problem scenario is---
In a Default.aspx page, I've 1 TextBox,1 Button,1 Label.

Page_load()
{
TextBox1.Text="SomeValue";
}
Button1_EventHandler()
{
Label1.Text=TextBox1.Text;
}


When the page loaded, then fine TextBox is having value 'SomeValue'.
Now suppose I enter some other value in TextBox say 'some other value' &
Button clicked.Now Label is showing 'SomeValue' instead of 'some other value'.

Plz..help me
Posted 13-Jan-13 1:04am
Updated 13-Jan-13 1:06am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

When you post a page back to the server, the Page Load event is always called. If you want to preserve values, then you need to check if this is the first time the page was loaded, or a reload due to post-back:
Page_load()
{
   if(!IsPostBack)
   {
      TextBox1.Text="SomeValue";
   }
}
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100