简体   繁体   English

c#UpdatePanel按钮单击将不起作用

[英]c# UpdatePanel button click won't work

Why my buttons won't work in update panel, but if I press "enter" key it's working? 为什么我的按钮在更新面板中不起作用,但是如果我按“输入”键,它就起作用了?

        <asp:ScriptManager ID="Sqrpt1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel UpdateMode="Always" ChildrenAsTriggers="true"  ID="updpan" runat="server"><ContentTemplate>
        <fieldset>
        <asp:Panel runat="server" ID="ClientSearchPa" DefaultButton="SearchClientPopup">
        <asp:TextBox ID="SearchClientBox" runat="server"></asp:TextBox>
&nbsp;<asp:Button ID="SearchClientPopup" runat="server" Text="Search" 
                onclick="SearchClientPopup_Click" /></asp:Panel>
        <br />
        <asp:ListBox ID="Clients" runat="server" Height="341px" Width="682px"></asp:ListBox>   

        <br />
        <br />
            <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
           <asp:Button ID="ClientSelect" runat="server" OnClick="ClientSelect_Click" Text="button" /> 
           </fieldset> 
        </ContentTemplate>
        </asp:UpdatePanel> 

Your code is perfectly alright and button are firing event on server side change your some control values in server events. 您的代码完全正确,服务器端的按钮触发事件会更改服务器事件中的某些控制值。 Your might not be noticing very fast response of ajax call 您可能没有注意到ajax调用的快速响应

  protected void SearchClientPopup_Click(object sender, EventArgs e)
    {
        SearchClientBox.Text = "Hello ajax SearchClient clicked";
    }
    protected void ClientSelect_Click(object sender, EventArgs e)
    {
        SearchClientBox.Text = "Hello ajax ClientSelect cliecked ";
    }
<asp:Panel runat="server" ID="ClientSearchPa" DefaultButton="SearchClientPopup"> 
<asp:TextBox ID="SearchClientBox" runat="server"></asp:TextBox> &nbsp;
<asp:Button ID="SearchClientPopup" runat="server" Text="Search" onclick= 

"SearchClientPopup_Click" /> “ SearchClientPopup_Click” />

 </asp:Panel> 

Here DefaultButton is set to SearchClientPopup.So if the focus is on any control within the Panel,then Enter key will work and SearchClientPopup will fire the click event. 这里的DefaultButton设置为SearchClientPopup。因此,如果焦点位于面板中的任何控件上,则Enter键将起作用,SearchClientPopup将触发click事件。

     <asp:Button ID="ClientSelect" runat="server" OnClick="ClientSelect_Click" Text="button" /> 

This button is not inside the panel control.So you have to explicitly fire it by clicking 此按钮不在面板控件内。因此,您必须通过单击来明确触发它

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

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