Ignas
Ignas

Reputation: 315

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> 

Upvotes: 1

Views: 2087

Answers (2)

Kanishka
Kanishka

Reputation: 71

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

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.

     <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

Upvotes: 0

Adil
Adil

Reputation: 148120

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

  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 ";
    }

Upvotes: 1

Related Questions