views:

15

answers:

2

I have a LinkButton in a web control and I want to bind the event at the page where I use this web control.

LinkButton's href attribute is renderedas below.

javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$CoreContent$Content$scale1", "", false, "", "/thema/fi/product/reviews.aspx", false, true))

It doesn't fire the event that I have attached in the web page.

My question is how this LinkButton is supposed to know that it should go to the event method I binded.

Thanks.

PS: I'm not asking how to bind an event to a linkbutton.

A: 

For our first point saying that the likn button event does not fire.

You have to call your javascript function in onclientclick event.

Example:

<asp:LinkButton ID="LinkButton1" runat="server" 
        onclientclick="Javascript:alert(&quot;s&quot;);">LinkButton</asp:LinkButton>
    </form>
Shoban
+1  A: 

This is handled by __doPostBack javascript function which sets __EVENTTARGET and __EVENTARGUMENT hidden fields. During server side life-cycle processing values from those fields are extracted and target control is searched. This control has to implement IPostBackEventHandler interface which defines RaisePostBackEvent method. The method raises an event and event handler is called. For link button the event is OnClick.

Ladislav Mrnka