473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Hi i want solution for following problem.

Hello i am developing an application in which user's data loaded on form load.so i keep that in page_load event. but when i try to save updated data using save_click event page_load event fires & previous data(same data) is inserted in database. so i want some other option to do this task.
please help me....
Expand|Select|Wrap|Line Numbers
  1.  protected void btnSave_Click(object sender, EventArgs e)
  2.         {
  3.             var newuser = new UserDetail
  4.             {
  5.                 firstname = txtFName.Text,
  6.                 lastame = txtLName.Text,
  7.                 address = txtAdd.Text,
  8.                 mobno = txtMobNo.Text,
  9.                 aboutme = txtAbtMe.Text,
  10.  
  11.             };
  12.             db.UserDetails.InsertOnSubmit(newuser);       
  13.           } 
  14.  
  15.  protected void Page_Load(object sender, EventArgs e)
  16.         {
  17.             UN = Session["MySession"].ToString();
  18.  
  19.             var query = from c in db.UserDetails
  20.                         where c.username == UN
  21.                         select new
  22.                         {
  23.                             firstname =c.firstname,
  24.                             lastame=c.lastame,
  25.                             address=c.address,
  26.                             mobno=c.mobno,
  27.                             aboutme=c.aboutme
  28.                         };
  29.  
  30.             foreach (var valuesFromQuery in query)
  31.             {
  32.  txtFName.Text = valuesFromQuery.firstname;
  33.                 txtLName.Text = valuesFromQuery.lastame;
  34.                 txtAdd.Text = valuesFromQuery.address;
  35.                 txtMobNo.Text = valuesFromQuery.mobno.ToString();
  36.                 txtAbtMe.Text = valuesFromQuery.aboutme; 
  37.             } 
  38.         }
  39.  
Oct 26 '10 #1
1 1389
Frinavale
9,735 Expert Mod 8TB
Only load the data the first time the page is loaded. You can accomplish this by checking the Page.IsPostback property. This property indicates whether or not a control on the page has "posted back" to the server for server side processing...if it is False then it is the first time the page is loading.

Try this:
Expand|Select|Wrap|Line Numbers
  1.  protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             UN = Session["MySession"].ToString();
  4.             if(IsPostBack == false){
  5.               var query = from c in db.UserDetails
  6.                         where c.username == UN
  7.                         select new
  8.                         {
  9.                             firstname =c.firstname,
  10.                             lastame=c.lastame,
  11.                             address=c.address,
  12.                             mobno=c.mobno,
  13.                             aboutme=c.aboutme
  14.                         };
  15.  
  16.               foreach (var valuesFromQuery in query)
  17.               {
  18.                   txtFName.Text = valuesFromQuery.firstname;
  19.                   txtLName.Text = valuesFromQuery.lastame;
  20.                   txtAdd.Text = valuesFromQuery.address;
  21.                   txtMobNo.Text = valuesFromQuery.mobno.ToString();
  22.                   txtAbtMe.Text = valuesFromQuery.aboutme; 
  23.               } 
  24.           }
  25.         }
  26.  
Oct 26 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Omar Vazquez | last post by:
HI, I HAD THIS PROBLEM TOO, I'M WORKING IN V.B. AND DB2 VER 8.1 WHEN I STARTED A TRANSACCTION I RECIVED THE SAME ERR CODE, THE PROBLEM WAS THAT I HAD A RECORSET OPEN(RESULSET IN JAVA), THE...
4
by: voidstar | last post by:
Hi, I have the following problem: I use "getch" to monitor keypresses and the I use "cin" to input a string. When I type in 'y', the 'y' character appears, so I need to hit backspace before...
0
by: Boniek | last post by:
Solution is CurrencyManager in Form.BindingContext. This collection has a list of CurrencyManager (manager of binded controls to the same source). One of them is CurrencyManager which has a...
1
by: Uriah Piddle | last post by:
Hi Gang, I posted this problem a few days ago and reported it solved but it appears that I was a bit hasty in declaring victory. The problem is this: when I create a new website in VS 2005...
0
by: kdilip41 | last post by:
Hi All, I would like to whether the following details is possible :: 1. 'How Many TSQL Statements Is Executed within a particular time frame say 8 hours and at the end of 8 hours i want a...
1
by: nondos | last post by:
Hi I have vb soultion with 5 projects i need to create one moudle file with var' which will be my program defintions and each project could access these var' How do i do it? Thanks
3
by: curiousEngine | last post by:
Hi. Am new to C++. Was trying some problems and wanted to verify the correct solution for this problem on the group: Write a program which reads a sequence of integers and counts how many...
1
by: fniles | last post by:
I just got a new machine and installed .NET 2005. In VB.NET 2005 in the old machine, under "Project" - "properties", in the "Compile" tab, I can see "Configuration" and "Platform" combo box with...
4
by: SamuelXiao | last post by:
-----------------------Lab002.h------------------------------ #ifndef _LAB_002_ #define _LAB_002_ class base{ char *msg; public: base(char *); ~base(); void print(void);
2
by: mahesh taru | last post by:
error: Microsoft VBScript runtime error '800a0046' Permission denied: 'CreateObject' /perdiemdev/rem/remitdetailsinexcel.asp, line 248 and on line no 248 , i have created server...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.