0

I have these tags

<li><a href="#view2" >Photo</a></li>
<li><a href="#view3">Data</a></li>
<li><a href="#view4">Cloud Shop</a></li>
<li><a href="#view5">Upload</a></li>
<li><a href="#view6">Site Check</a></li>
<li><a href="#view7">Others</a></li>

I want to invoke them from code behind using c#. How can I achieve this?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Trax
  • 341
  • 4
  • 17
  • 2
    Define "invoke", especially in this context. – CodeCaster Jun 25 '14 at 10:41
  • If by 'invoke' you mean access their details then you can add a runat=server tag and an ID to each one. Then just call the ID in the codebehind and add / edit details there. NOTE: This won't give you the same level of control as a asp:hyperlink – Full Time Skeleton Jun 25 '14 at 10:41
  • By "invoke" what I mean is I want to call the click events of these anchor tags using c#. – Trax Jun 25 '14 at 10:43
  • You can't. A ["pound sign href", "fragment" or "named anchor"](http://stackoverflow.com/questions/2800187/what-is-it-when-a-link-has-a-pound-sign-in-it) usually just causes the _browser_ to scroll to the named element, unless there's some JavaScript attached that handles the click event. The JavaScript code runs _after_ your C# code. Explain what the serverside C# code should do with these links and when. – CodeCaster Jun 25 '14 at 10:44
  • Use `LinkButton`, you can call `Click` on them. – Bharadwaj Jun 25 '14 at 10:45
  • are you fine with jquery?? – Neel Jun 25 '14 at 12:00

1 Answers1

0

This will allow you access to the tags:

<li><a ID="lnk1" runat="server" href="#view2" >Photo</a></li>
<li><a ID="lnk2" runat="server" href="#view3">Data</a></li>
<li><a ID="lnk3" runat="server" href="#view4">Cloud Shop</a></li>
<li><a ID="lnk4" runat="server" href="#view5">Upload</a></li>
<li><a ID="lnk5" runat="server" href="#view6">Site Check</a></li>
<li><a ID="lnk6" runat="server" href="#view7">Others</a></li>

Then in code behind you can do something like:

lnk4.Attributes.Add("class","active");

To give the link a css class of active.

UPDATE: I see you want access to the click events, I'd recommend using a LinkButton instead, easier to work with.

Full Time Skeleton
  • 1,680
  • 1
  • 22
  • 39