0

hi my dear firends :
i have a button like below :

            <p id="EnterToImagesParag" class="EnterParag">
                <a id="EnterToImagesLink" name="EnterToImagesLink" class="EnterLink">
                </a>
            </p>

and css :

p.EnterParag, p.EnterParag a.EnterLink
{
   width: 400px;
   height: 45px;
   display: block;
}
p#EnterToImagesParag
{
    background: url(/Images/Admin/btnConfigImages.png) 0px -45px;
}
p#EnterToImagesParag a#EnterToImagesLink
{
    background: url(/Images/Admin/btnConfigImages.png) 0px 0px;
}

and jquery Like this :

        $(document.body).ready(function () {
            $('.EnterParag a').hover(
            function () { $(this).stop().animate({ 'opacity': '0' }, 500); },
            function () { $(this).stop().animate({ 'opacity': '1' }, 500); });
});

how can i add server side event click to this button ?

thanks in advance

SilverLight
  • 19,668
  • 65
  • 192
  • 300

2 Answers2

3

To clarify, that's not a button, it's an anchor. You can add a server side event by adding runat=server and an event handler for the OnServerClick event.

 <a id="EnterToImagesLink" name="EnterToImagesLink" class="EnterLink" runat="server" OnServerClick="MyClickEvent"> </a>
keyboardP
  • 68,824
  • 13
  • 156
  • 205
  • @keyboardP thanks for attention -> just a moment / i am testing it! – SilverLight Jun 04 '11 at 16:25
  • ok / it works perfect / thanks a lot! but is there another way/s for learning? – SilverLight Jun 04 '11 at 16:34
  • @LostLord - Arief's suggestion of using `asp:LinkButton` can also be used as well. You can also use jQuery to handle the click and fire a server side event (using `eval`). An example of that is here: http://praveenbattula.blogspot.com/2009/08/call-aspnet-server-side-event-in-jquery.html Depending on your needs, you can also use jQuery with AJAX http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/ – keyboardP Jun 04 '11 at 16:37
  • +1: really wonderful. i didnt even know `OnServerClick` existed. wow. things i learn everyday :) – naveen Jun 04 '11 at 16:41
  • It's why I love SO - I always learn at least one new thing each visit :) – keyboardP Jun 04 '11 at 16:45
1

you can replace the anchor element "a" with ASP.NET control LinkButton control, it will produce the same type of HTML element (anchor/"a") and it provides you with Click event as well (server side).

<asp:LinkButton ID="myLinkButton" runat="server" CssClass="EnterLink" Text="My LinkButton" OnClick="OnServerClickMethod" />
Arief
  • 6,055
  • 7
  • 37
  • 41
  • pal hyperlink doesn't have a click event. alter before somebody -1 you. :) – naveen Jun 04 '11 at 16:23
  • @LostLord, you can still apply styling on server controls. Use CssClass property to set CSS class to server control. – Arief Jun 04 '11 at 16:28
  • +1: it happens all day for me :) but i think keyboardP answer is more apt to the context :) – naveen Jun 04 '11 at 16:40