We help IT Professionals succeed at work.
Get Started

ASP.Net - Error: Invalid postback or callback argument.

P1ST0LPETE asked
Last Modified: 2013-12-17

[Sections of relevant code are attached below]

I am using the AjaxControlToolkit ModalPopupExtender to create a message box for my web app.  To reduce lines of code, I have the Panel that is serving as the message box on my master page, and then when I want to access/show the message box from one of my content pages I just do something like this:

Label messageBoxMessage =  (Label)page.Master.FindControl("lbMessageBoxMessage");
private ModalPopupExtender ajaxPopupExtender = (ModalPopupExtender)page.Master.FindControl("MessageBoxExtender");

messageBoxMessage.Text = "bla bla bla";

This has been working for me just fine until the current page I'm working on.  On this current page I have an asp:UpdatePanel and inside of the update panel I have a dropdownlist that is dynamically created.  I have the OnSelectedIndexChanged event on the dropdownlist set to trigger an anychronous event (which it does just fine) and depending on which option was selected I want to fire my message box.  However, when I try to show the message box, the labels show up blank (i.e. no text in them) and when I click on the link button that I have within the message box I get the following error:

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

I have been doing some testing, and I am able to show my message box from all other event firing controls on the page, except for controls created dynamically that are inside the update panel.

Also, I have placed another modal popup panel directly on the content page I'm currently working on (out side of the update panel) and I am able to open this one up just fine from the dynamically created dropdownlist inside the update panel.  This is going against what I'm an trying to do though, because placing a modal popup on the content page means more code, when I should be able to use the one on the master page.

So in summary:
- I am able to successfully show the modal popup on my master page from events on my content pages
- However I am not able to successfully show the modal popup on my master page from events fired from dynamically created controls inside an update panel on a content page.
- I am able to successfully show a modal popup on my content page, from events fired from dynamically created controls inside an update panel on the same content page.

What do I need to do to enable me to display the message box on my master page from an event fired from a dynamically created control inside an update panel?

//Message Box on Master Page:
<asp:Panel ID="pnlMessageBox" runat="server" CssClass="MessageBox">
    <div class="MessageBoxHeader">
    <asp:Label ID="lbMessageBoxTitle" runat="server" />
    <div class="MessageBoxContent">
        <asp:Button ID="HiddenTrigger" runat="server" Style="display: none" />
        <asp:HiddenField ID="hfClickStatus" runat="server" />
        <asp:Label ID="lbMessageBoxMessage" runat="server" />
        <br />
        <asp:TextBox ID="tbMessageBoxInput" runat="server" Width="280" OnKeyPress="return AlphaNumericKeyPress(event)" />
    <div class="MessageBoxButtons">
        <asp:LinkButton ID="linkNoCancel" runat="server" OnClientClick="MessageBoxClickStatus(this)" />
        <asp:LinkButton ID="linkYesOk" runat="server" OnClientClick="MessageBoxClickStatus(this)" />
<ajax:ModalPopupExtender ID="MessageBoxExtender" runat="server" BackgroundCssClass="ModalBackground"
        TargetControlID="HiddenTrigger" PopupControlID="pnlMessageBox" />

//Update Panel on Content Page:
<asp:UpdatePanel ID="ProgramGrid" runat="server" UpdateMode="Conditional">
        <asp:Panel ID="headerRow" runat="server" CssClass="HeaderRow" />
        <br />
        <asp:Panel ID="ProgramStages" runat="server" />
        <div id="HiddenData">
            <asp:HiddenField ID="hfRowComments" runat="server" />
            <asp:HiddenField ID="hfSelectedRow" runat="server" />
            <asp:HiddenField ID="hfRowCount" runat="server" />
        <asp:AsyncPostBackTrigger ControlID="lkAddRowAbove" />
        <asp:AsyncPostBackTrigger ControlID="lkAddRowBelow" />
        <asp:AsyncPostBackTrigger ControlID="lkDeleteRow" />

//DropDownList being dynamically created and added to UpdatePanel:
for (int row = 1; row <= dataTable.Rows.Count; row++)
    Panel stage = new Panel();
    stage.ID = "Stage" + row;
    stage.CssClass = "Row";

    //Controls added to stage panel

    DropDownList typeDDL = CreateDDLCell(row, 2);
    typeDDL.AutoPostBack = true;
    typeDDL.SelectedIndexChanged += new EventHandler(BlastChillType_SelectedIndexChanged);
    typeDDL.Attributes.Add("OnFocus", "CloseDropDown(); RecordBlastChillType(this)");
    typeDDL.Attributes.Add("OnChange", "RecordBlastChillType(this)");
    AddCellToRow(ref stage, typeDDL);

    //More controls added to stage panel

    //DropDownList added to UpdatePanel here:

//DropDownList SelectedIndexChanged Event:
protected void BlastChillType_SelectedIndexChanged(object sender, EventArgs e)
    DropDownList ddl = (DropDownList)sender;
    if (ddl.SelectedValue == "DEFROST")
        if (ProgramGridData.Rows.Count <= 16)
            //Some irrelevant code
            ModalPopupExtender ajaxPopupExtender = (ModalPopupExtender)page.Master.FindControl("MessageBoxExtender");
            Label message = (Label)page.Master.FindControl("lbMessageBoxMessage");
            message = "You can't have more than 20 stages";

Open in new window

Watch Question
This problem has been solved!
Unlock 3 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE