0

The reason I ask is because I have an Update Panel filled with textboxes, labels, etc. that I make visible/invisble depending on what the user clicks. Later, I run a loop to clear all the textboxes. It used to work just fine, but now that I've added the AJAX Update Panel, it gives me an "Invalid postback or callback argument" error.

Is this because of that AJAX Update Panel? Or am I doing something completely wrong on my own?

Thanks, Ellie

[EDIT]: Okay, I'm adding a whole bunch of code because I have no idea where it's coming from:

This is the method to write the record:

protected void AddEmployerRecord()
    {
        connection = new SqlConnection();
        connection.ConnectionString = "****";
        connection.Open();

        newEmployer = new EmployerCRUD(connection);

        employerRow.employerName = tb_employer.Text;
        employerRow.empPhone = tb_phone.Text;
        employerRow.empFax = tb_fax.Text;
        employerRow.empEmail = tb_email.Text;
        employerRow.empAddress = tb_address.Text;
        employerRow.empCity = tb_city.Text;
        employerRow.empState = ddl_state.SelectedValue.ToString();
        employerRow.empZIP = tb_ZIP.Text;
        employerRow.startDate = Convert.ToDateTime(tb_fromDate.Text);
        employerRow.endDate = Convert.ToDateTime(tb_toDate.Text);
        employerRow.startPay = Convert.ToDecimal(tb_startPay.Text);
        employerRow.endPay = Convert.ToDecimal(tb_endPay.Text);
        employerRow.leaveReason = tb_leaveReason.Text;
        employerRow.supervisorFName = tb_superFName.Text;
        employerRow.supervisorLName = tb_superLName.Text;
        employerRow.contactForRef = rbl_contact.SelectedValue.ToString();
        employerRow.jobDesc = tb_jobDesc.Text;
        employerRow.applicantID = 10010;
        //employerRow.applicantID = Convert.ToInt32(Session["ApplicantNum"]);
        employerRow.supervisorTitle = tb_superTitle.Text;
        employerRow.jobTitle = tb_jobTitle.Text;
        employerRow.startPayType = ddl_startPayType.SelectedValue.ToString();
        employerRow.endPayType = ddl_endPayType.SelectedValue.ToString();

        ct_emp = newEmployer.Add(employerRow);
        // *************** Error Message *************** //
        //if (ct_emp.Message != "OK")
        //    Error message
        //else
        //    

        connection.Close();
    }

And this is the method to load the grid:

protected void LoadGrid()
    {
        try
        {
            SqlConnection pConnection = new SqlConnection();
            pConnection.ConnectionString = "**";
            pConnection.Open();
            string sqlstatement = "SELECT EmployerID, EmployerName FROM dbo.EMPLOYER WHERE ApplicantID = @applicantID";
            command = new SqlCommand(sqlstatement, pConnection);
            command.Parameters.AddWithValue("@applicantID", 10010);
            //command.Parameters.AddWithValue("@applicantID", Session["ApplicantNum"].ToString().Trim());
            ds = new DataSet();
            adapter = new SqlDataAdapter(command);
            builder = new SqlCommandBuilder(adapter);
            adapter.Fill(ds);
            gv_employers.DataSource = ds.Tables[0];
            gv_employers.DataBind();
            pConnection.Close();
        }
        catch (Exception error)
        {
            Response.Write(error.Message);
        }
    }

Just as a sidenote, ApplicantID is only 10010 while I debug things (need consistency).

Also, I read somewhere that this problem occurs when you try to re-bind the data to the grid. I run that LoadGrid() method each time the page is reloaded. Should I bind the data somewhere else? If so, how?

  • Can you post the code that you are using to clear the text boxes as well as the code where the error in the invalid postback is occuring..? – MethodMan Aug 01 '12 at 19:00
  • It could be that you are being caught out by the difference between a postback and an asyncpostback. See http://stackoverflow.com/questions/2278891/asynchronous-and-synchronous-postback-in-asp-net or http://stackoverflow.com/questions/228969/invalid-postback-or-callback-argument-event-validation-is-enabled-using-page for example – dash Aug 01 '12 at 19:06

2 Answers2

0

if you want a simple way to clear all text boxes use something like this

    public  void ClearTextItems(ControlCollection controls)
    {
        foreach (Control c in controls)
        {
            if (c is System.Web.UI.WebControls.TextBox)
            {
                TextBox t = c as TextBox;
                t.Text = string.Empty;
            }
        }
     }

will need to see the other code where you are getting the PostBack Error...

MethodMan
  • 18,625
  • 6
  • 34
  • 52
0

Just adding an UpdatePanel should not cause that error.

UpdatePanels envelope a part of the page and cause partial refreshes to that part.

Are you updating the controls collection? Adding controls or user controls dynamically depending on some user input?

Check for additions to the ViewState or controls collection on controls.

nunespascal
  • 17,584
  • 2
  • 43
  • 46