Search code examples
c#asp.netbuttonpostbacklinkbutton

UpdatePanel with Button / LinkButton doesnt work


Im trying to resolve an issue with a button / link-button (both doesnt work). The problem is the following:

I have a navigation menu where the user can choose the "tab" (view of Multiview) where he wants to be redirected to. In this menu i have some buttons / link-buttons which should update the updatepanel. But it doesnt do that - it always updates the whole page.

Some of my ASCX-Code:

    <div class="row">
                <label style="margin-left: 15px">Menu</label><br />
                <div class="col-sm-4 col-md-3 sidebar">
                    <div class="mini-submenu">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </div>
                    <div class="list-group">
                        <span class="list-group-item active">Woundmanagement

                            <span class="pull-right" id="slide-submenu">
                                <i class="fa fa-times"></i>
                            </span>
                        </span>
                          <asp:Button ID="Button_1" runat="server" Text="Wundbeschreibung" CssClass="list-group-item" OnClick="nav_btn_1_Click" />
...
more items in the dropdownmenu

</div>...

The event which should be fired when clicking the button:

protected void nav_btn_1_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 1;

        }

I searched for 2 hours now and tried every possible solution - what i tried until now:

  • Put the Button and the menu inside and outside the update panel - doesnt change the problem

  • added PostbackTrigger

      <asp:PostBackTrigger ControlID="Button_1"/>
    

This way my button work, but still the page is reloaded

  • then i added the asyncPostbackTrigger

      <asp:AsyncPostBackTrigger ControlID="Button_1" EventName="Click"/>
    

if i click the button now, nothing happens.

  • i tried to add UpdateMode conditional to the updatePanel

      <asp:ScriptManager ID="ScriptManager1" runat ="server"> 
      </asp:ScriptManager>
      <asp:UpdatePanel ID="UP_Woundmanagement" runat="server" 
      UpdateMode="Conditional">
    
  • i moved the <Triggers> in front of the updatePanel and behind the updatePanel

  • i added ClientIDMode="AutoID" to the page directive

  • tried the same things with LinkButton

I dont really know what i can further try to make it work, would be great if someone of you guys got an idea! :)


Solution

  • I don't understand why you didn't share your updatepanel aspx code. Triggers tag inside update panel not before or after it.

    <script runat="server">
       protected void Button1_Click(object sender, EventArgs e)
       {
         Label1.Text = "Refreshed at " + DateTime.Now.ToString();
       }
    </script>
    
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button1" />
            </Triggers>
        </asp:UpdatePanel>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> 
    </div> 
    

    If trigger objects will be inside of UpdatePanel, you should set ChildrenAsTrigger as true. And if your update panel in a ContentPlaceHolder this article will be useful for you. https://msdn.microsoft.com/tr-tr/library/bb398864(v=vs.100).aspx