UpdatePanel and UserControl.

  • Thread starter Tino Donderwinkel
  • Start date
T

Tino Donderwinkel

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top