Click here to Skip to main content
Rate this: bad
good
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 0:04am
Edited 13-Jan-13 0: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
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 231
3 Sergey Alexandrovich Kryukov 211
4 kbrandwijk 204
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 405
4 thatraja 370


Advertise | Privacy | Mobile
Web04 | 2.8.140902.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2014
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