IsPostBack Issue

72 views Asked by At

I am trying to do a 3 tier volunteers sign up for packaging session system. First, on the page load, I get the details of certain packaging session:

        if (!IsPostBack)
        {
            string packingID = Request.QueryString["id"];

            packingIndv = packing.getPacking(packingID);
            if (packingIndv == null)
            {
                lbl_msg.Text = "Error in getting packing session details!";
            }
            else
            {
                lbl_ID.Text = packingIndv.packingID;
                lbl_date.Text = packingIndv.date.ToString("dd/M/yyyy", CultureInfo.InvariantCulture); ;
                lbl_location.Text = packingIndv.location;
                lbl_volunteerAvailable.Text = packingIndv.volunteerAvailable.ToString();
                lbl_status.Text = packingIndv.status;
            }
        }

After that, volunteers can click on the join button, and the program will execute:

In presentation layer after join button is on click:

string userLogged = Session["userLogged"].ToString();
        UserBLL user = new UserBLL();
        string userID = user.getUserIDByName(userLogged);

        PackingBLL packing = new PackingBLL();
        string msg = "";
        msg = packing.joinPacking(userID, lbl_ID.Text);
        lbl_msg.Text = msg;

In business logic layer:

public string joinPacking(string userID, string packingID)
    {
        string returnMessage = "";

        if(returnMessage.Length == 0)
        {
            Packing packing = new Packing(userID, packingID);
            Boolean success = packing.checkJoinedSession();
            if (success)
            {
                returnMessage += "Same volunteer cannot join same packing session for more than once! <br/>";
            }
            else
            {
                int nofRows = 0;
                nofRows = packing.joinPacking();

                if (nofRows > 0)
                {
                    returnMessage = "Request to volunteer for packing session saved successfully.";
                    int successUpdate = packing.updateRemaining();
                    if (successUpdate > 0)
                    {
                        getPacking(packingID);
                    }
                }
                else
                {
                    returnMessage = "Error! Please try again.";
                }
            }
        }

        return returnMessage;
    }

In data access layer:

 public int updateRemaining()
    {
        int result = 0;

        using (var connection = new SqlConnection(FFTHDb.connectionString)) // get your connection string from the other class here
        {
            SqlCommand command = new SqlCommand("UPDATE PackingSession SET volunteerAvailable = volunteerAvailable + 1 WHERE packingID = '" + packingID + "'", connection);
            connection.Open();
            result = command.ExecuteNonQuery();
            connection.Close();
        }
        return result;
    }

For every join from each volunteer, the volunteer available will be increased by one. What I am trying to do is from the page load, I display the details of packaging session. Then when volunteer joins it, the volunteerAvailable will straight away increased by one. All my database works perfectly, it just wont increase the volunteer available automatically after each successful update sql statement, as in I have to refresh the browser in order to see the changes.

0

There are 0 answers