1

为什么我的按钮在更新面板中不起作用,但如果我按“enter”键它就起作用了?

        <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> 
4

2 回答 2

1

您的代码完全没问题,并且按钮正在服务器端触发事件,更改您在服务器事件中的一些控制值。您可能没有注意到 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 ";
    }
于 2012-04-18T10:30:23.443 回答
0
<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> 

这里 DefaultButton 设置为 SearchClientPopup。因此,如果焦点位于面板内的任何控件上,则 Enter 键将起作用,SearchClientPopup 将触发单击事件。

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

此按钮不在面板控件内。因此您必须通过单击显式触发它

于 2012-04-18T11:05:53.130 回答