locked
button inside updatepanel is not firing RRS feed

  • Question

  • User736276958 posted

    Hi all,

    In my page iam using 4 dropdown and 4 buttons.

    based on first dropdown selection, second dropdown is filling and so  on

    for each dropdown i have added a button

    these all controls are inside the updatepanel.

    dropdowns are working fine without reloading the page, but buttons are not firing.

    below is my code

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
    <Triggers>
    <asp:AsyncPostBackTrigger controlid="ibtndist" eventname="Click" />
    </Triggers>
    <ContentTemplate>
    <table >
    <tr>
    <td>
    <asp:Label ID="Label1" runat="server" Text="country"></asp:Label>
    </td>
    <td>
    <asp:dropdownlist ID="ddlcountry" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlcountry_SelectedIndexChanged"></asp:dropdownlist>
    </td>
    <td>

    <asp:LinkButton ID="ibtncountry" runat="server" Width="25%" Height="25%" OnClick="ibtncountry_Click"></asp:LinkButton>
    </td>
    </tr>

    <tr>
    <td>
    <asp:Label ID="Label2" runat="server" Text="state" ></asp:Label>
    </td>
    <td>
    <asp:dropdownlist ID="ddlstate" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlstate_SelectedIndexChanged" >
    <asp:ListItem>Select</asp:ListItem>
    </asp:dropdownlist>

    </td>
    <td>
    <asp:LinkButton ID="ibtnstate" runat="server" Width="25%" Height="25%" OnClick="ibtnstate_Click"></asp:LinkButton>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="Label4" runat="server" Text="city"></asp:Label>
    </td>
    <td>
    <asp:dropdownlist ID="ddlcity" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlcity_SelectedIndexChanged">
    <asp:ListItem>Select</asp:ListItem>
    </asp:dropdownlist>
    </td>
    <td>
    <asp:LinkButton ID="ibtncity" runat="server" Width="25%" Height="25%" OnClick="ibtngp_Click"></asp:LinkButton>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="Label5" runat="server" Text="Villages"></asp:Label>
    </td>
    <td>
    <asp:dropdownlist ID="ddlvillages" runat="server" AutoPostBack="True">
    <asp:ListItem>Select</asp:ListItem>
    </asp:dropdownlist>
    </td>
    <td>
    <asp:LinkButton ID="ibtnvill" runat="server" Width="25%" Height="25%" OnClick="ibtnvill_Click"></asp:LinkButton>
    </td>
    </tr>

    </table>

    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger controlid="ibtncountry" eventname="Click" />
    </Triggers>
    </asp:UpdatePanel>

    i have just added only one control in trigger, but it is not working

    please correct my code

    Tuesday, October 20, 2015 8:08 AM

Answers

  • User61956409 posted

    Hi rishe28,

    on dropdown change page should not be refreshed but on button click, page has to be refreshed.

    You could try to set the button as PostBackTrigger instead of AsyncPostBackTrigger.

    <asp:PostBackTrigger ControlID="ibtncountry" />

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2015 3:16 AM

All replies

  • User2103319870 posted

    dropdowns are working fine without reloading the page, but buttons are not firing.
    <Triggers>
    <asp:AsyncPostBackTrigger controlid="ibtndist" eventname="Click" />
    </Triggers>

    Not sure if this is causing any problem, but when I look at the code I noticed that you have added a trigger to ibtnDist button and the button control is not present the code provided. I have removed it from your code and tried and the button postback happened successfully.

    Another reason could be if you have any validation on page that might stop the page postback on button click. You can set the CausesValidation property of button to resolve this

    <asp:LinkButton ID="ibtncountry" runat="server" Width="25%" Height="25%" OnClick="ibtncountry_Click" CausesValidation="false">Test</asp:LinkButton>

    Tuesday, October 20, 2015 3:45 PM
  • User61956409 posted

    Hi rishe28,

    Firstly, as a2h said, we could not find a control with id called “ibtndist”. Do you get this error message?

    Secondly, the following code works fine on my side, the click event of linkbutton “ibtncountry” could be fired.

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <table>
                    <tr>
                        <td>
                            <asp:Label ID="Label1" runat="server" Text="country"></asp:Label>
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlcountry" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlcountry_SelectedIndexChanged">
                                <asp:ListItem>country1</asp:ListItem>
                                <asp:ListItem>country2</asp:ListItem>
                                <asp:ListItem>country3</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td>
                            <asp:LinkButton ID="ibtncountry" runat="server" Width="25%" Height="25%" Text="btncountry" OnClick="ibtncountry_Click"></asp:LinkButton>
                        </td>
                    </tr>
                </table>
                <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ibtncountry" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
    
    </div> 
    
    protected void ibtncountry_Click(object sender, EventArgs e)
    {
        string str = "hello world";
        Label2.Text = str;
    }

    Best Regards,

    Fei Han

    Wednesday, October 21, 2015 1:47 AM
  • User736276958 posted

    hi,

    Thanks for ur reply.

    button is firing, but page is not refreshing.

    on dropdown change page should not be refreshed but on button click, page has to be refreshed.

    in my page dropdowns and buttons are in dialog box and map in a parent page

    ie on button click selected country has to be zoomed in the parent page.

    i have checked on runtime, button clcik event is firing but parent page is not reloading.

    Wednesday, October 21, 2015 2:11 AM
  • User61956409 posted

    Hi rishe28,

    on dropdown change page should not be refreshed but on button click, page has to be refreshed.

    You could try to set the button as PostBackTrigger instead of AsyncPostBackTrigger.

    <asp:PostBackTrigger ControlID="ibtncountry" />

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2015 3:16 AM