简体   繁体   English

asp.net UpdatePanel无法正常工作

[英]asp.net UpdatePanel not working correctly

Im using an UpdatePanel to refresh a datagrid with some search results but is not working and the whole page goes in postback. 我使用UpdatePanel刷新带有一些搜索结果的数据网格,但无法正常工作,整个页面都回发。 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>

Some solutions: 一些解决方案:

a. 一种。 Try Giving UpdateMode = Conditional in the UpdatePanel and try ( when you give triggers you must define this ) 尝试在UpdatePanel中提供UpdateMode = Conditional ,然后尝试(提供触发器时必须定义此条件)

b. b。 Try removing the <table> , and replace it with <div> , sometimes Update Panels are not friendly with the table tag. 尝试删除<table> ,然后将其替换为<div> ,有时Update Panels与table标记不兼容。

c. 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. d。 I see user controls getting called - check if you have update panel inside those user controls placed properly. 我看到用户控件被调用-检查这些用户控件中的更新面板是否放置正确。

This looks like a familiar .NET Bug. 这看起来像是一个熟悉的.NET Bug。 Setting ClientIDMode="AutoID" on the LinkButton should fix it (by the way, you can remove the trigger. It's not needed). 在LinkBut​​ton上设置ClientIDMode =“ AutoID”应该可以解决此问题(顺便说一下,您可以删除触发器。不需要这样做)。

在UpdatePanel中使用它:

UpdateMode="Conditional" ChildrenAsTriggers="true"

Check that your HTML source does not have 2 or more <form> tags. 检查您的HTML源代码是否没有2个或多个<form>标记。 An asp.net page is supposed to ordinarily have only one <form> tag. 一个asp.net页通常应该只有一个<form>标记。

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. 当您在某段HTML中有一个<form>标记,然后将该HTML片段插入母版页已经存在的<form>标记中时,就会遇到问题。 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. 取而代之的是,尽管有更新面板,整个页面还是会刷新,而且还可能在页面的URL中添加查询字符串。

The nested <form> tag of the master page is at the cause of this. 母版页面的嵌套<form>标记是造成这种情况的原因。 As soon as you remove the extra <form> tag everything should work fine. 删除多余的<form>标记后,一切都应正常工作。

Hope this helps someone. 希望这对某人有帮助。

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 不要忘记将更新面板的UpdateMode属性设置为Conditional

Here is a reference :: Using Triggers in an UpdatePanel in ASP.NET 4.0 C# 这是参考:::在ASP.NET 4.0 C#中的UpdatePanel中使用触发器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM