Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
Go Back  Xtreme Visual Basic Talk > > > Web Part Input Form: Update only fields that have changed


Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2008, 09:54 AM
Beth Beth is offline
Centurion
 
Join Date: Feb 2005
Posts: 109
Default Web Part Input Form: Update only fields that have changed


Hi, I'm currently working on a web part in VB.NET to allow users to update their personal info in our user database. (stuff like phone number and address)

The entire webpart consists of the input form and a submit button. (and some validation controls that I'll add in later)

When the page first loads, data is pulled from the DB and the textboxes are populated. When the Submit button is clicked, the information is gathered from the form, and the user's records will be updated in our database.

What I would like is to have a way to check if a field has been changed by the user. This way I can selectively update fields in the database, instead of updating all fields, regardless of whether or not they have been changed by the user.
Reply With Quote
  #2  
Old 11-24-2008, 03:47 PM
Beth Beth is offline
Centurion
 
Join Date: Feb 2005
Posts: 109
Default

I decided to use some hidden fields to store the initial form values, which I could eventually compare with the visible user-input fields.

I was having major problems getting values from my second (hidden) set of textboxes, and after digging around through information about the lifecycle of Web Parts, I started looking at other solutions to my problem.

Indeed, when my textboxes are hidden, the values could not be retrieved.

Instead of using textboxes and hiding them:
Code:
Dim txtPhoneHidden As New TextBox
'...
txtPhoneHidden.Visible = False
'...
phone = txtPhoneHidden.Text
I had to use a 'hiddenField' object:
Code:
Dim txtPhoneHidden As New HiddenField
'...
phone = txtPhoneHidden.Value.ToString
I honestly don't know if this is proper, I just figured out that it was a workable solution for me, and I'm just about to head home for the day. Figured I would leave a response in case anyone was looking for an answer.
Reply With Quote
  #3  
Old 11-24-2008, 09:47 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

Correct or not what is the reason for not updating everything all at once? On the database side of things, it is just as quick to update 100 things as it is to update 1. The server code you're going to need to check what needs updating and what does not will most take longer than just updating the fields.

On the database side of things, if you want to know what changed, most DB's have a parameter you can use which will tell you if a column was really changed, then you can return it back to the ASP code. Another way is to use some kind of trigger.

Either way, if it works, it works. Not necessarily the best or fastest way to do things though, at least in my opinion.
Reply With Quote
  #4  
Old 12-11-2008, 11:07 AM
John_0025 John_0025 is offline
Freshman
 
Join Date: Sep 2003
Posts: 39
Default

I agree with Targe that the effort of checking if the value is changed is going to take longer than simply updating all the fields.

With regards to hiding controls you might be interested to know.

Code:
Dim txtPhoneHidden As New TextBox
'...
txtPhoneHidden.Visible = False
'...
phone = txtPhoneHidden.Text
If you set Visible to false it will prevent the control rendering in the page, so it doesn't exist on the client and can not return a value.

Code:
txtPhoneHidden.Style["visibility"]= "hidden";
This will render the textbox allowing it to return a value but will not display it to the user, howerver the rest of the page will render as if it exists.

Code:
txtPhoneHidden.Style["display"]= "none";

This will render the textbox but will not display it to the user and render the rest of the page as if it doesn't exist.

Simple hey Hidden fields are meant to contain hidden data so probably the best choice.
Reply With Quote
  #5  
Old 12-11-2008, 09:30 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

If you're using the CSS property of Display: None just be aware that it does render the information on the client side and script editors like Google's inspect feature can simply change it to appear.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
 
Web Part Input Form: Update only fields that have changed
Web Part Input Form: Update only fields that have changed
 
-->