带有 asyncpostback 触发器的 UpdatePanel 无法正常工作并导致奇怪的行为
UpdatePanel with asyncpostback trigger doesn't work correctly and causes weird behavior
这里发生了一些奇怪的事情。我目前有一个下拉列表 drpIntervention
,它有 autopostback="true",直到现在我一直在调用服务器代码,根据 selected 值是什么来控制 disable/enable。我不喜欢回传的闪烁,所以我试图用 AsyncPostBack 触发器将代码包装在 UpdatePanel
中,但奇怪的事情正在发生:
这是此更新 panl 的代码:
<asp:UpdatePanel ID="UpdatePanel5" runat ="server" UpdateMode ="Conditional">
<ContentTemplate >
<tr>
<td colspan="3" class="questionFont">
<table style="width:100%; border-collapse:collapse ">
<tr>
<td>
<b>a. What is the Problem?</b>
</td>
<td >
<asp:DropDownList ID="drpCrisisType" runat="server" autopostback="true" Enabled ="false" OnSelectedIndexChanged="drpCrisisType_SelectedIndexChanged ">
</asp:DropDownList>
<span runat="server" style="font-size:12px; font-family :'Times New Roman';" ID="Span16"><i>(Description)</i></span>
</td>
</tr>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpIntervention" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
这是应该触发事件的按钮的代码,它在 updatePanel 之外
<tr>
<td class="questionFont" style="padding-top: 20px">
<b>4. Did you engage in any?</b>
</td>
<td style="padding-top: 20px">
<asp:DropDownList ID="drpIntervention" runat="server" autopostback="true" OnSelectedIndexChanged="drpIntervention_SelectedIndexChanged ">
</asp:DropDownList>
</td>
</tr>
所以这不是我的全部代码,<tr>
属于一个table,上面还有很多,这个更新面板和下拉只是其中的一部分。发生的事情是,我在浏览器中加载页面,一切看起来都很好,然后我 select drpIntervention
中的一个值和内容(其他下拉菜单,以及具有 enabling/disabling 服务器代码的文本框)包装在更新面板中的内容被移动到页面中其他内容的上方。更奇怪的是,被移动的内容在不执行 postback
的情况下也能正常工作,但是内容也在其原始位置并且在那里不起作用。
我希望我说得有道理,只要我 select 来自 drpIntervention
的值,更新面板中的内容就会出现在页面的两个位置。脑洞大开!
我认为问题与我放置 asp:update panel
的位置有关。因为我把它放在 table 中,所以它以某种方式覆盖了格式并将更新面板中的内容带到 table.
的顶部
解决问题的方法是我为这个问题创建了一个 table,并将整个 table 包裹在 asp:update panel
中。这解决了问题
这里发生了一些奇怪的事情。我目前有一个下拉列表 drpIntervention
,它有 autopostback="true",直到现在我一直在调用服务器代码,根据 selected 值是什么来控制 disable/enable。我不喜欢回传的闪烁,所以我试图用 AsyncPostBack 触发器将代码包装在 UpdatePanel
中,但奇怪的事情正在发生:
这是此更新 panl 的代码:
<asp:UpdatePanel ID="UpdatePanel5" runat ="server" UpdateMode ="Conditional">
<ContentTemplate >
<tr>
<td colspan="3" class="questionFont">
<table style="width:100%; border-collapse:collapse ">
<tr>
<td>
<b>a. What is the Problem?</b>
</td>
<td >
<asp:DropDownList ID="drpCrisisType" runat="server" autopostback="true" Enabled ="false" OnSelectedIndexChanged="drpCrisisType_SelectedIndexChanged ">
</asp:DropDownList>
<span runat="server" style="font-size:12px; font-family :'Times New Roman';" ID="Span16"><i>(Description)</i></span>
</td>
</tr>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpIntervention" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
这是应该触发事件的按钮的代码,它在 updatePanel 之外
<tr>
<td class="questionFont" style="padding-top: 20px">
<b>4. Did you engage in any?</b>
</td>
<td style="padding-top: 20px">
<asp:DropDownList ID="drpIntervention" runat="server" autopostback="true" OnSelectedIndexChanged="drpIntervention_SelectedIndexChanged ">
</asp:DropDownList>
</td>
</tr>
所以这不是我的全部代码,<tr>
属于一个table,上面还有很多,这个更新面板和下拉只是其中的一部分。发生的事情是,我在浏览器中加载页面,一切看起来都很好,然后我 select drpIntervention
中的一个值和内容(其他下拉菜单,以及具有 enabling/disabling 服务器代码的文本框)包装在更新面板中的内容被移动到页面中其他内容的上方。更奇怪的是,被移动的内容在不执行 postback
的情况下也能正常工作,但是内容也在其原始位置并且在那里不起作用。
我希望我说得有道理,只要我 select 来自 drpIntervention
的值,更新面板中的内容就会出现在页面的两个位置。脑洞大开!
我认为问题与我放置 asp:update panel
的位置有关。因为我把它放在 table 中,所以它以某种方式覆盖了格式并将更新面板中的内容带到 table.
解决问题的方法是我为这个问题创建了一个 table,并将整个 table 包裹在 asp:update panel
中。这解决了问题