简体   繁体   English

ASP.NET页面事件-必须单击两次按钮才能触发事件

[英]ASP.NET page events - Button has to be clicked twice to fire event

I have an imageButton with a few controls(2 dropdowns, 3 textboxes) inside an UpdatePanel. 我在UpdatePanel中有一个带几个控件的imageButton(2个下拉列表,3个文本框)。

When I change the text of any of the textboxes, the ImageButton needs to be clicked twice to fire the onClick event. 当我更改任何文本框的文本时,都需要单击ImageButton两次以触发onClick事件。

I just don't get why it happens, since I have any events associated with the textboxes. 我只是不知道为什么会这样,因为我有与文本框相关的任何事件。

Any ideas? 有任何想法吗?

Thanks! 谢谢!

Ok, just editing to show up my code. 好的,只需编辑以显示我的代码即可。

This is the UpdatePanel where things are: 这是UpdatePanel所在的位置:

<asp:UpdatePanel ID="upBusca" runat="server"><ContentTemplate>
<asp:UpdateProgress ID="pMaster" runat="server"><ProgressTemplate><div id="loaderOverlay"></div><div id="loader"><img alt="Carregando..." src='<%# "/imagens/" + ThemeName + "/loading.gif" %>' /><p>Carregando...</p></div></ProgressTemplate></asp:UpdateProgress>
<div style="float:left" id="busca">
<img src='<%# "/imagens/" + ThemeName + "/busca-fundo-e.jpg" %>' class="esquerda" alt=""/>
<img src='<%# "/imagens/" + ThemeName + "/busca-fundo-d.jpg" %>' class="direita" alt=""/> 
<p class="titulo">Utilize os campos abaixo para filtrar as operações registradas.</p>    
<div style="float:left">
<p><b>Status:</b></p>
<asp:DropDownList ID="ddlStatus" runat="server">
    <asp:ListItem Selected="True" Value="T">Todos os títulos</asp:ListItem>
    <asp:ListItem Value="3">Título liberado para antecipação</asp:ListItem>
    <asp:ListItem Value="4">Antecipação solicitada</asp:ListItem>
    <asp:ListItem Value="2">Título pago</asp:ListItem>
    <asp:ListItem Value="5">Título não liberado para antecipação</asp:ListItem>
</asp:DropDownList><br />
<p><b>Data:</b></p>
    <asp:DropDownList ID="ddlData" runat="server" AutoPostBack="True" 
        onselectedindexchanged="ddlData_SelectedIndexChanged">
        <asp:ListItem Selected="True">-- Selecione --</asp:ListItem>
        <asp:ListItem Value="dataEmissao">Emissão</asp:ListItem>
        <asp:ListItem Value="solicitacao">Solicitação</asp:ListItem>
        <asp:ListItem Value="vencimento">Vencimento</asp:ListItem>
        <asp:ListItem Value="pagamento">Pagamento</asp:ListItem>
    </asp:DropDownList>
    &nbsp;&nbsp;<asp:TextBox ID="txtDtInicial" runat="server" AutoPostBack="True" 
        Visible="False"></asp:TextBox>
    <asp:Label ID="lblA" runat="server" Text="à" Visible="False"></asp:Label>
    <asp:TextBox ID="txtDtFinal" runat="server" AutoPostBack="True" Visible="False"></asp:TextBox>
    <br />
<p><b>Nº Solicitação:</b></p>
<asp:TextBox ID="txtSolicitacao" runat="server" AutoPostBack="True" ></asp:TextBox>
    <br />
<p><b>Valor:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R$</p>
 <asp:TextBox ID="txtValor" runat="server"
    AutoPostBack="True" MaxLength="12" 
        onkeypress="javascript:mascara(this, soMoeda);"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<cc1:MaskedEditExtender ID="meDataD" runat="server" TargetControlID="txtDtInicial" 
        ClearMaskOnLostFocus="False" Mask="99/99/9999">
</cc1:MaskedEditExtender>
<cc1:MaskedEditExtender ID="meDataAte" runat="server" TargetControlID="txtDtFinal" 
        ClearMaskOnLostFocus="False" Mask="99/99/9999">
</cc1:MaskedEditExtender>
    <asp:ImageButton ID="imbBuscar" runat="server" 
        ImageUrl="~/imagens/Default/bt-busca.jpg" onclick="imbBuscar_Click" />
<br />     
</div>
<div style="float:left">    
<p><b>Número NF:</b></p>
<asp:TextBox ID="txtNf" runat="server" AutoPostBack="True" ></asp:TextBox>
    <br />     
</div>
</div><!-- Busca -->    
<hr />
</ContentTemplate>
</asp:UpdatePanel>

I'm not adding any controls on the page load. 我没有在页面加载中添加任何控件。

I'm guessing that you're adding the controls to the page dynamically, and you're doing it differently every time. 我猜想您是将控件动态添加到页面中,并且每次都以不同的方式进行操作。 If you change the order of the controls when you add them to the page, it won't find the right control to hook up the event to, because the ID's will be different. 如果在将控件添加到页面时更改控件的顺序,则将找不到正确的控件将事件挂接到该控件,因为ID会有所不同。

I'd really need to see your code to diagnose it properly though. 不过,我确实需要查看您的代码才能对其进行正确诊断。 You'll need to provide a lot more detail. 您需要提供更多详细信息。

This may not be the answer and I'm just throwing it out there, but I see you're using extender controls attached to the textboxes. 这可能不是答案,我只是把它扔在那里,但我看到您正在使用附加到文本框的扩展控件。 Personally I've found the MS ajax control toolkit extenders often interfere with basic functionality, especially the MaskedEditExtender . 我个人发现MS ajax控制工具包扩展程序经常会干扰基本功能,尤其是MaskedEditExtender

Try temporarily removing the extenders, see if the problem persists. 尝试暂时卸下扩展器,看问题是否仍然存在。

I treat the control extenders like beta releases because they are soo buggy. 我将控件扩展程序视为Beta版本,因为它们太过马车了。

Have you run this in a debugger to make sure the onclick handler isn't actually getting called the first time? 您是否已在调试器中运行此程序以确保onclick处理程序并未真正被首次调用?

I've seen cases like this where an event handler does actually get fired, but due to the order of things done in the code behind, the results of the changes from the event aren't rendered to the browser until the next request is made. 我已经看到了这样的情况,其中事件处理程序确实被触发了,但是由于后面代码中的处理顺序,事件的更改结果直到下一个请求发出时才呈现给浏览器。 。

So next time you click the button, the same event handler is called again, but what gets rendered back to the client are actually the changes that were made in the previous call. 因此,下次单击该按钮时,将再次调用相同的事件处理程序,但是呈现回客户端的实际上是在上一次调用中所做的更改。

Typically this kind of thing happens if you are databinding in page_load but not re-binding in the actual event handler. 通常,如果您要在page_load中进行数据绑定,而不是在实际事件处理程序中进行重新绑定,则会发生这种情况。 I see this a LOT with various grid components, especially with sorting and paging events. 我看到这是一个包含各种网格组件的批处理,尤其是排序和分页事件。

We'd need to see the full example to diagnose exactly where the problem is though. 我们需要查看完整的示例以准确诊断问题出在哪里。

Have you looked at the generated HTML to make sure that it seems OK? 您是否查看了生成的HTML以确保它看起来还可以?

Have you watched the HTTP conversation with a web debugger like Fiddler? 您是否看过与Fiddler之类的Web调试器进行的HTTP对话?

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

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