asp.netjqueryupdatepanelviewstateblockui

JQuery BlockUI with UpdatePanel Viewstate Issue


I have an update panel within a div that I modal using the JQuery plugin BlockUI. Inside the UpdatePanel is a textbox and a button. When I enter something in the textbox and click the button I am unable to retrieve the text in the textbox. When I debug it shows the textbox having no value.

<asp:UpdatePanel ID="upTest" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
        <div id="divTest">
            <asp:TextBox ID="txtTestVS" runat="server" /><br />
            <asp:Button ID="cmdTest" Text="TEST" OnClick="cmdTest_Click" UseSubmitBehavior="false" runat="server" />
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

SERVER-SIDE:

protected void cmdTest_Click(object sender, EventArgs e)
{
    string x = txtTestVS.Text;
}

This should clarify things. Here are the total contents of the page.

<a href="javascript:$.blockUI({ message: $('#divTest') });">SHOW MODAL</a>

<div id="divTest">
    <asp:UpdatePanel ID="upTest" UpdateMode="Conditional" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="txtTestVS" runat="server" /><br />
            <asp:Button ID="cmdTest" Text="TEST" OnClick="cmdTest_Click" UseSubmitBehavior="false" runat="server" />
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

Solution

  • This is a common problem with dialog plug-ins. The problem is when content is put in the blockUI container, it's appended to the element, and no longer in the form being submitted to the server. To solve this you need to edit the blockUI code a bit:

    Here's the source: http://github.com/malsup/blockui/blob/master/jquery.blockUI.js

    Change this: Line 262:
    var layers = [lyr1,lyr2,lyr3], $par = full ? $('body') : $(el);
    to:
    var layers = [lyr1,lyr2,lyr3], $par = full ? $('form') : $(el);

    and this:

    Line 382:
    els = $('body').children().filter('.blockUI').add('body > .blockUI');
    to:
    els = $('form').children().filter('.blockUI').add('form > .blockUI');

    That should get you going and the textbox values coming through.

    (Response courtesy of Nick Craver https://stackoverflow.com/users/13249/nick-craver)