CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2002
    Location
    Devon, UK
    Posts
    212

    [RESOLVED] Updating a form, Postback, general confusion

    I have a form containing a dropdownlist. Whatever is selected in the dropdownlist gets loaded in the subsequent textboxes, checkboxes, etc. I then have a button to be used to apply changes.

    Page_Load goes something like this:
    Code:
    if (IsPostBack)
    {
        LoadSelectedInfo();
    }
    else
    {
        LoadList();
        SelectFirst();
        LoadSelectedInfo();
    }
    ButtonClick goes something like this:
    Code:
    if (List.SelectedIndex >= 0)
    {
        string strSelected = List.SelectedValue;
        bool bChanged = false;
        CurrentInfo = LoadInfo(strSelected);
    
        if (FirstTextBox.Text.CompareTo(CurrentInfo.FirstText) != 0)
        {
            CurrentInfo.FirstText = FirstTextBox.Text;
            bChanged = true;
        }
    
        if (FirstCheckBox.Checked != CurrentInfo.FirstCheck)
        {
            CurrentInfo.FirstCheck = FirstCheckBox.Checked;
            bChanged = true;
        }
    
        if (bChanged)
        {
            UpdateDatabase();
        }
    }
    The problem is that the Page_Load fires which loads the current info into the form, so when the subsequent Button_Click event fires, the values to be updating with have been filled so the values to be updated are lost.

    How is this kind of stuff normally achieved? Any ideas? Have I been clear in my explanation?

    Thanks for your time,
    T
    Some cause happiness wherever they go; others, whenever they go.

  2. #2
    Join Date
    Nov 2002
    Location
    Devon, UK
    Posts
    212

    Re: Updating a form, Postback, general confusion

    Duh - ListBox_SelectedIndexChanged, not Page_Load !!
    Some cause happiness wherever they go; others, whenever they go.

  3. #3
    Join Date
    Jan 2008
    Location
    Atlanta, Georgia - United States
    Posts
    75

    Re: [RESOLVED] Updating a form, Postback, general confusion

    Did you rep yourself?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured