gicio Posted October 22, 2003 Posted October 22, 2003 Hi! At first I tell you what I will do: 1. Load data from DB 2. Fill System.Web.UI.WebControls.TextBox with data from DB 3. Than the user can change some data in the System.Web.UI.WebControls.TextBox and now how I can compare what the user change? should I add a new Item to Context.Items and compare it after changes? any idea? regards, gicio Quote
kw_wainwright Posted October 22, 2003 Posted October 22, 2003 When you load the data from the DB, store it in 2 textboxes (or two places, they don't both have to be textboxes). Then when the user changes one, compare the text to the original (the other unchanged textbox). It should be easy enough to compare to strings. Quote
gicio Posted October 22, 2003 Author Posted October 22, 2003 thx! but where is the best place to store the data???? Context.Items ???? regards, gicio Quote
kw_wainwright Posted October 22, 2003 Posted October 22, 2003 Is "Context" the textbox or what? It really doesn't matter where the data is stored, but what I was recommending was that you store it in two textboxes. One that the user can edit "tbUser.Text", and the other being the original "tbOriginal.Text". Maybe we are mis-understanding each other. If you are not sure what I am talking about, then please elaborate on your use of Context.Items (possibly with some code). Quote
*Gurus* Derek Stone Posted October 22, 2003 *Gurus* Posted October 22, 2003 Context.Items is not what you're looking for. Once the user posts the page back with any changes the database should be requeried and comparisons should be made from there. If you don't do it in such a manner your application is going to suffer huge concurrency issues. Quote Posting Guidelines
gicio Posted October 22, 2003 Author Posted October 22, 2003 private void FillControlsWithData() { UsersDB currentUsersDB = new UsersDB(); SqlDataReader dr = currentUsersDB.GetSingleUser(Context.User.Identity.Name); // Read first row from database dr.Read(); Context.Items.Add("UserFirstName",(String) dr["FirstName"]); dr.Close(); m_txtFirstName.Text = Context.Items["UserFirstName"].ToString() } private void m_cmdChangeData_Click(object sender, System.EventArgs e) { if( !(m_txtFirstName.Text == Context.Items["UserFirstName"].ToString()) ) { //make something stuff here!!!! } } In the if( !(m_txtFirstName.Text == Context.Items["UserFirstName"].ToString()) ) I get an error: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 169: { Line 170: if( !(m_txtFirstName.Text == Context.Items["UserFirstName"].ToString()) ) Line 171: { Line 172: //make something stuff here!!!! Source File: c:\inetpub\wwwroot\immo\desktopmodules\usereditdata.ascx.cs Line: 170 Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] OcImmobilienPortal.UserEditData.m_cmdChangeData_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\immo\desktopmodules\usereditdata.ascx.cs:170 System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) System.Web.UI.Page.ProcessRequestMain() any idea what the problem is? regards, gicio Quote
*Gurus* Derek Stone Posted October 22, 2003 *Gurus* Posted October 22, 2003 Context.Items is not persisted across multiple requests. Please read my post above. Quote Posting Guidelines
gicio Posted October 23, 2003 Author Posted October 23, 2003 and what about saving the data so: ViewState["MyData"] = MyTextBox.Text; ??? regards, gicio Quote
*Gurus* Derek Stone Posted October 23, 2003 *Gurus* Posted October 23, 2003 Please reread my post. I've clearly stated why that is not a good idea. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.