UpdatePanel and UserControl.

Discussion in 'ASP .Net' started by Tino Donderwinkel, Apr 9, 2010.

  1. Hi,

    I have create two simple UserControls that use UpdatePanels internally.
    These UserControls are used on a 'main' page.

    Both UserControls reside in a seperate UpdatePanel on the 'main' page. These
    UpdatePanels hold logic for 'updating' the UserControls;

    <asp:UpdatePanel ID="updatePanel1" runat="server" ChildrenAsTriggers="False"
    UpdateMode="Conditional" EnableViewState="False">
    <ContentTemplate>
    <asp:TextBox ID="textBox1" Text="something"
    runat="server"></asp:TextBox>
    <asp:Button ID="button1" runat="server" Text="Load..."
    CausesValidation="false" onclick="button1_Click" />
    <uc1:UserControl ID="uc1" runat="server" EnableViewState="false" />
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="button1" EventName="Click" />
    </Triggers>
    </asp:UpdatePanel>

    The code behind the button1_Click event is;

    protected void button1_Click(object sender, EventArgs e)
    {
    uc1.Property = textBox1.Text;
    uc1.Update();
    }

    Now, all UserControls work perfectly well independently. The UpdatePanel on
    the 'main' page makes sure only the UserControl I want to update is updated.

    But if I put two different UserControls in seperate UpdatePanels on the
    'main' page, buttons inside the UserControls throw the dreaded
    Sys.WebForms.PageRequestManagerServerErrorException exception when the
    postback of UpdatePanel of the OTHER UserControl is triggered after the last
    postback of the UpdatePanel I clicked the button in. (Still with me?)

    To clarify; This Exception ONLY occurs if I do this (or vice versa):

    Click 'button1' to 'update' the first UpdatePanel that has UserControl1.
    (Now here, I can do anything I want to UserControl1; all buttons (triggers)
    can be clicked, and the UserControl1 refreshes perfectly. It behaves as
    expected.)

    Click 'button2' to 'update' the second UpdatePanel that has UserControl2.
    (Now here, I can do anything I want to UserControl2; all buttons (triggers)
    can be clicked, and the UserControl2 refreshes perfectly. It behaves as
    expected.)

    If I click 'button1' again to update the first UpdatePanel that has
    UserControl1, the control is 'updated' and can be used as expected. (great)

    Now for the problem;

    If I Click on a trigger button in UserControl2, the dreaded exception is
    raised;

    Microsoft JScript runtime error:
    Sys.WebForms.PageRequestManagerServerErrorException: 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.

    So if I do anything that triggers a postback of a UserControl that is NOT
    the UserControl that was last 'updated' by one of the buttons/UpdatePanels
    on the 'main' page, the error occurs.

    The UserControls have been designed in such a way that they do not rely on
    ViewState. (There is only one important property, and that is held in
    ControlState.)

    I'm using Visual Studio 2010 RC1 with the .NET Framework 4.0 RC.

    The ScriptManager I'm using on the 'main' Page is the AJAX Toolkit
    ScriptManager and is compiled from the latest build against .NET 4.0.

    So what's causing this and how can I resolve this issue? (And please don't
    say I have to disable EventValidation...)

    Thanks,

    Tino
    Tino Donderwinkel, Apr 9, 2010
    #1
    1. Advertising

  2. Kobus van Jaarsveldt, Aug 31, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    473
    Rob Meade
    Aug 8, 2007
  2. zb
    Replies:
    1
    Views:
    621
    PJ on Development
    Nov 8, 2007
  3. Leon Mayne
    Replies:
    5
    Views:
    4,742
    Leon Mayne
    May 27, 2008
  4. ree321
    Replies:
    1
    Views:
    1,473
    ree321
    Apr 20, 2009
  5. Nathan Sokalski
    Replies:
    1
    Views:
    577
    miher
    Jun 15, 2009
Loading...

Share This Page