开发者

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.

When I change the text of any of the textboxes, the ImageButton needs to be clicked twice to fire the onClick event.

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:

<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" ru开发者_JS百科nat="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.

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.

Try temporarily removing the extenders, see if the problem persists.

I treat the control extenders like beta releases because they are soo buggy.


Have you run this in a debugger to make sure the onclick handler isn't actually getting called the first time?

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. 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?

Have you watched the HTTP conversation with a web debugger like Fiddler?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜