Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# a new feature would be nice, is it there?

Posted on 2009-07-13
17
Medium Priority
?
183 Views
Last Modified: 2012-05-07
I have a web based C# .net 2008 form that is used for updating records.
I have about 13 fields and the user can update any record, so there is an 'update' button as well as a 'add new' button and a 'reset'.
So if the user clicks on 'add new' I would like to make sure they have not update any information on the fields, because if they dont hit submit, all the changes would be lost. So I was hoping to do a check (is there some built in feature), that I can check to see if any values were changed, if so, prompt them to save because the code for 'Add New' is run.
0
Comment
Question by:lobos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
  • +2
17 Comments
 
LVL 22

Accepted Solution

by:
p_davis earned 100 total points
ID: 24840901
do you use datatables/datasets to bind to these fields? if so then it would be fairly easy.

there are addnew rejectchanges and acceptchanges methods on both. you can check datarowstates to see if something has been added or modified.
0
 
LVL 21

Expert Comment

by:silemone
ID: 24840939
No, there is no way to do this from a built in control...

This is how I did this:

1) On page load, i created a ViewState object for each control...and loaded the value of it...   ViewState.Add("ControlAVal", ConrtrolA.Value)

2)  Then I can compare it to that...if (! ViewState["ControlAVal"].ToString().Equals(ControlA.Value)){ //means change occured...add logic }
0
 
LVL 21

Assisted Solution

by:silemone
silemone earned 100 total points
ID: 24841070
oops...


page load:

when you load control value from db if that's where you getting them from you would also load viewstate value

//loaded control value  and use control
Viewstate.Add("SomeControlValue", SomeControl.Text) ; //say if its a textbox

then later when finding controls which have been changed (this may be for the purpose of creating a list to past as a parameter for a sproc, or just in page)

if (!ViewState["SomeControlVal"].ToString().Equals(SomeControl.Text) )
{
         //add to string builder, comma delimited string for parameter list or do build a SQL statement  in code, or whatever
         //at the end of logic do this:
        ViewState.Add("SomeControlVal", SomeControl.Text);         //Value updated so that next go around, it will evaluate new val...
}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 21

Expert Comment

by:silemone
ID: 24841079
oops = i should have given an example...so there you have one...
0
 

Author Comment

by:lobos
ID: 24852404
ok thanks for the comments...this leads to this question...how is what is the best recommended way to load the values to the text fields....I have always done it this way below....is this the best way or is there another more efficient, microsoft recommended way based on your comments I'm not sure which way to go...
      this.txtLocation.Text = ds.Tables[0].Rows[0]["Location"].ToString();
      this.txtWebsite.Text = ds.Tables[0].Rows[0]["Website"].ToString();
      this.txtName.Text = ds.Tables[0].Rows[0]["Name"].ToString();
      this.txtEmail.Text = ds.Tables[0].Rows[0]["Email"].ToString();

Please advise, thanks.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24852484
txtLocation.DataBindings.Add("Text", ds.Tables[0], "Location");
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24852503
this.txtWebsite.DataBindings.Add("Text ",  ds.Tables[0], "Website");
      this.txtName.DataBindings.Add("Text ", ds.Tables[0],"Name");
      this.txtEmail.DataBindings.Add("Text ", ds.Tables[0],"Email");
0
 
LVL 21

Expert Comment

by:silemone
ID: 24852712
your way is ok...no difference.
0
 
LVL 1

Expert Comment

by:chicabow
ID: 24852739
what advantages are there of doing the way p_davis has displayed?
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24852820
umm except with binding the updates to the record are handled already. also record states and if htere is more than one row -- say attached to a grid  whatever current record you are view would be updated in the text fields --


i would say that there is a big difference.
0
 
LVL 21

Expert Comment

by:silemone
ID: 24852847
chica, there aren't really any...if there was a lot of data, databinding may be quicker because the coding behind it is by microsoft themselves (which supposedly makes it more refined than our for loops), but as i stated also, there is no need for lobos to change his code.
0
 
LVL 6

Expert Comment

by:ahmad2121
ID: 24852866
to answer the original question, it can be even simpler than that. Have one bool, set it to false on load, for every textbox, use the textchanged event to set it to true. In your button, if that bool is true, ask them to save.
0
 
LVL 21

Expert Comment

by:silemone
ID: 24852892
that's what i was doing with with my code ID:24841070...forgot to set a flag element to false...good catch ahmad
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24852895
how do you know what lobos's setup is - it might be very beneficial for this to be implemented with databindings. i even use databinding with generic lists -- rowstates have to be handled on your side but it is still a nice way to handle row changes.
0
 
LVL 21

Expert Comment

by:silemone
ID: 24853748
i think we're just saying binding one piece of data is overkill...its agreed if he was populating a huge table, binding would be quicker on the coding and functioning side...
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24853950
agreed
0
 

Author Closing Comment

by:lobos
ID: 31602882
thanks for all feedback.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question