更改下拉列表选择会导致完全回发。 (这比听起来更有趣)
这是场景。
我有一个带有文本框的搜索页面,允许用户输入搜索词并按 Enter 键。 (这会触发 TextChanged)。我有一个 DropDownList 指定将执行的搜索类型。它在标记中定义如下:
<asp:DropDownList ID="lstSearchType" runat="server" AutoPostBack="false">
<asp:ListItem Value="0">Last, First</asp:ListItem>
<asp:ListItem Value="1">Last</asp:ListItem>
<asp:ListItem Value="2">First</asp:ListItem>
<asp:ListItem Value="3">Liberty ID</asp:ListItem>
<asp:ListItem Value="4">E-mail</asp:ListItem>
<asp:ListItem Value="5">Telephone</asp:ListItem>
<asp:ListItem Value="6">Birthday (exact m/d/yyyy)</asp:ListItem>
<asp:ListItem Value="7">SSN (exact ###-##-####)</asp:ListItem>
<asp:ListItem Value="8">Address</asp:ListItem>
</asp:DropDownList>
如您所见,AutoPostBack 设置为 false,并且没有事件连接。
按 Enter 会触发 TextBox 的 OnTextChanged 事件,该事件执行搜索并更新 UpdatePanel 中的 GridView。此 UpdatePanel 将其 UpdateMode 设置为条件式,并具有一个触发器:搜索 TextBox 的 TextChanged 事件。
这很简单。
而且它几乎工作得很漂亮。
每当我更改搜索类型时,下一个搜索都会进行完整回发。所有后续搜索都会进行部分回发(根据需要),除非我再次更改搜索类型。
此规则有一个例外:如果我加载页面并立即更改搜索类型,它不会执行完整的回发。因此,在任何回发(完整或部分)之前 DropDownList 的第一次更改不会触发完整回发。
全面披露: 我正在执行大量 JavaScript 来更改异步请求期间 gridview 的外观。我在这里不详细说明,因为它似乎无关。仅当更改未连接 JavaScript 的 DropDownList 时,才会出现此问题。
有什么想法吗?
这让我发疯。其他一切都正常。
提前致谢, 克利夫
Here's the scenario.
I have a search page with a TextBox that allows someone to type in a search term and press enter. (Which fires TextChanged). I have a DropDownList that specifies the kind of search that will be performed. It is defined in the markup as follows:
<asp:DropDownList ID="lstSearchType" runat="server" AutoPostBack="false">
<asp:ListItem Value="0">Last, First</asp:ListItem>
<asp:ListItem Value="1">Last</asp:ListItem>
<asp:ListItem Value="2">First</asp:ListItem>
<asp:ListItem Value="3">Liberty ID</asp:ListItem>
<asp:ListItem Value="4">E-mail</asp:ListItem>
<asp:ListItem Value="5">Telephone</asp:ListItem>
<asp:ListItem Value="6">Birthday (exact m/d/yyyy)</asp:ListItem>
<asp:ListItem Value="7">SSN (exact ###-##-####)</asp:ListItem>
<asp:ListItem Value="8">Address</asp:ListItem>
</asp:DropDownList>
As you can see, AutoPostBack is set to false, and there is no event hookup.
Pressing enter fires the OnTextChanged event for the TextBox, which performs a search and updates a GridView in an UpdatePanel. This UpdatePanel has its UpdateMode set to conditional and has one trigger: the TextChanged event of the search TextBox.
It's very simple.
And it works beautifully, almost.
Whenever I change the search type, the very next search does a full postback. All subsequent searches do partial postbacks (as desired) unless I change the search type again.
There is one exception to this rule: if I load the page and immediately change the search type, it doesn't do a full postback. So the first change of the DropDownList before any postback (full or partial) does not trigger a full postback.
Full Disclosure:
I'm doing a lot of JavaScript to change the appearance of the gridview during async requests. I don't detail it here because it seems unrelated. This problem only occurs when a DropDownList with no JavaScript wired up is changed.
Any ideas?
This is driving me crazy. Everything else is working.
Thanks in advance,
Clif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。问题是 DropDownList 不在 UpdatePanel 中。如果不进行完整的回发,它就无法获取该值。由于 TextChanged 事件连接,TextBox 不受此影响。
I figured it out. The problem was that the DropDownList was not in an UpdatePanel. It had no way to get the value without doing a full postback. The TextBox was immune to this because of the TextChanged event wiring.