asp.net UpdatePanel not working correctly

22.4k Views Asked by At

Im using an UpdatePanel to refresh a datagrid with some search results but is not working and the whole page goes in postback. i hope somebody can help me, cant get this to work right. . Thanks. Here is my code:

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="left" class="pageTitle" valign="top">
                        <twc:LocalizedLiteral Text="CRMcontxt6" runat="server" />
                    </td>
                </tr>

                    <tr align="left" style="background-color: #9bbbe3">
                        <td align="left" colspan="3">
                            <asp:Label ID="lblSearch" Height="15" runat="server" Font-Bold="true" Font-Size="11"></asp:Label>
                            <asp:TextBox Width="500px" ID="Search" autoclick="BtnSearch" runat="server" CssClass="boxDesign" />
                            <asp:LinkButton  ID="BtnSearch" runat="server" CssClass="save" />
                         </td>
                    </tr>
                </table>

                   <asp:datagrid id="searchresults" runat="server">
           </ContentTemplate>

             <Triggers>
                <asp:AsyncPostBackTrigger ControlID="BtnSearch" />
            </Triggers>
            </asp:UpdatePanel>
5

There are 5 best solutions below

4
On

You missed the trigger event. Your trigger should look like this

<Triggers>
            <asp:AsyncPostBackTrigger ControlID="BtnSearch" EventName="Click" />
</Triggers>

Don't forget to set the UpdateMode attrivute of the update panel to Conditional

Here is a reference :: Using Triggers in an UpdatePanel in ASP.NET 4.0 C#

1
On

Some solutions:

a. Try Giving UpdateMode = Conditional in the UpdatePanel and try ( when you give triggers you must define this )

b. Try removing the <table>, and replace it with <div>, sometimes Update Panels are not friendly with the table tag.

c. If above does not work, first try removing the triggers, and the update mode condition and see whether that works. Because if that doesn't work, it means something wrong with the content inside the update panel. You may want to start with some controls to drill down your problem.

d. I see user controls getting called - check if you have update panel inside those user controls placed properly.

0
On

This looks like a familiar .NET Bug. Setting ClientIDMode="AutoID" on the LinkButton should fix it (by the way, you can remove the trigger. It's not needed).

0
On

Use this in UpdatePanel:

UpdateMode="Conditional" ChildrenAsTriggers="true"
1
On

Check that your HTML source does not have 2 or more <form> tags. An asp.net page is supposed to ordinarily have only one <form> tag.

Though this question has been long asked without an answer so far, I faced a similar problem, but discovered the cause of the update panel not working:

When you have a <form> tag in some piece of HTML and then insert that HTML fragment inside the already existing <form> tag of your master page, you get into problems. Each time the child page of the master page is run, and the submit button is clicked, the code the button is supposed to run wont execute. Instead the whole page gets refreshed despite the update panel, and it might also add a query string in the URL of the page.

The nested <form> tag of the master page is at the cause of this. As soon as you remove the extra <form> tag everything should work fine.

Hope this helps someone.