Thursday, March 4, 2010

MVC & ViewState don't work together

It seems that postbacks are not supported in MVC. I found this article, and tried to address this issue in order to use some Ajax controls that do require form tags for including a ScriptManager, which cause postbacks.

In short - it worked correctly, with one tweak: instead of
public class ViewUserControlWithoutViewState<T> : ViewUserControl<T> where T : class 
I changed to:
public class ViewUserControlWithoutViewState : ViewUserControl
Otherwise, ASP.Net was not finding the type. Why? Didn't dig into more, but it may be related to Reflection not resolving correctly when where keyword is being used.

BTW - this is the control I was trying to use (needs Ajax Controls Toolkit):
    <form id="Form1" runat="server">
<asp:ToolkitScriptManager ID="asm" runat="server" />
<asp:LinkButton ID="linkButton1" runat="server" Text="Show Popup" />
<asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="linkButton1" ConfirmText="Want it or not?" />
</form>

No comments: