0

I am having to have 2 buttons to correctly behave inside a div.

If I set a single button redirecting to a code behing method, it works fine:

<div class="divBtNavCommande">
     <asp:LinkButton ID="bt_1" runat="server" OnClick="myAction">
      My text 1
     </asp:LinkButton>                  
</div>

If I add a second buttons redirecting to a link, the redirection works fine but the first button nolonger performs the code behind action:

 <div class="divBtNavCommande">
     <asp:LinkButton ID="bt_1" runat="server" OnClick="myAction">
       My text 1
     </asp:LinkButton>

     <asp:LinkButton ID="bt_2" runat="server" PostBackUrl="~/MyPage.aspx">
       My text 2
     </asp:LinkButton>
</div>

And if I remove the PostBackUrl="~/myPage.aspx"part, the first button works again.

What is wrong?

Jaydip Jadhav
  • 12,179
  • 6
  • 24
  • 40
A.D.
  • 1,062
  • 1
  • 13
  • 37

1 Answers1

0

YourPage.aspx:

<div class="divBtNavCommande">
 <asp:LinkButton ID="bt_1" runat="server" OnClick="myAction">
   My text 1
 </asp:LinkButton>

 <asp:LinkButton ID="bt_2" runat="server" OnClick="bt_2_OnClick">
   My text 2
 </asp:LinkButton>
</div>

YourPage.aspx.cs:

protected void bt_2_OnClick(object sender, EventArgs e)
{
    Response.Redirect("MyPage.aspx");
}

Because you said that it was for nagivation purposes only. Otherwise use Server.Transer(); more info here: https://stackoverflow.com/a/6778952/169714

Community
  • 1
  • 1
JP Hellemons
  • 5,977
  • 11
  • 63
  • 128
  • That would work, this is what I had in mind. Thanks. Do you know why the solution that I posted does not work although both buttons operate correctly separately if I add only one of the 2 buttons (any of the 2), but do not work if the 2 buttons are present? – A.D. Nov 03 '16 at 14:18
  • Perhaps your `Page_Load` show some more code behind ;) As said here https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.postbackurl(v=vs.110).aspx perhaps the server-side validation? I need more context I think. – JP Hellemons Nov 03 '16 at 14:23