0

basically I have a button in my navbar which is defined in master file. And I want to call a c# method when that button**(bt)** is clicked. But I can not access the control in code-behind. I also need to control visibility, so I believe it has to stay in one of those Views.

<asp:GridView   runat="server" ID="lw3">
                   <EmptyDataTemplate>
                        <ul class="nav navbar-nav navbar-right" style="color:#ffffff !important">
                             <li><a runat="server" href=""></a></li>
                              <li><a runat="server" href="" title=""></a></li>
                               <li><a runat="server" id="btout">bt</a></li>

                            </ul>
                   </EmptyDataTemplate>
                </asp:GridView>
  • I see no buttons that are webforms controls. So while you can manipulate your `` because they are `runat="server"`, you won't be able to easily run the server method when it is clicked - see http://stackoverflow.com/questions/2476982/how-to-let-html-link-anchor-do-a-postback-to-be-like-linkbutton. You'd better just use full-blown asp control - it will be much simpler. – Eugene Podskal Mar 12 '16 at 18:21

1 Answers1

2

Put the <a> link outside of Gridview to directly access in code behind.

If you still want to put inside the grid then you will be able to access these <a> link through grid by doing lw3.FindControl.

After you get access to those control then you will be able to control visibility as well by doing: btout.Visible = true; or btout.Visible = false;

I Hope this will help you.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Nabin
  • 163
  • 1
  • 12