How to find out in Page_Load which linkbutton event is fired?

  • Thread starter Thread starter Andreas Klemt
  • Start date Start date
A

Andreas Klemt

Hello,
how can I find out in Page_Load which linkbutton event is fired?

Thanks for any help in advance!!
Andreas
 
I might need more detail behind your question, but in short it depends on where your linkbutton is

If you just dropped it on the form directly, then all you need is an event handler with Handles MyLinkButton.Click (VB syntax)

If it's part of a bigger control, like a datalist or a datagrid, then you need to handle MyDataList.ItemCommand, which gets the click event for all buttons within that container. If you have multiple buttons, then in that event handler you want to check conditionally for which specific button was clicked. Easiest way is when you add the linkbutton to the control, set the CommandName property--i.e. MyButton1, MButton2, etc.--then in your event handler you can do a case statement on e.item.CommandName to get the button. You can also set CommandArgument, which lets you pass an additional argument to your handler when the button is clicked

hth

Bill Bor

----- Andreas Klemt wrote: ----

Hello
how can I find out in Page_Load which linkbutton event is fired

Thanks for any help in advance!
Andrea
 
Hello Bill,

thanks for your answer.
I am looking for a way how I can see in a Page_Load which LinkButton is
clicked
from other UserControls. Is there a way to see it in Page_Load?

Thanks for any help!!
Kind Regards
Andreas


Bill Borg said:
I might need more detail behind your question, but in short it depends on where your linkbutton is.

If you just dropped it on the form directly, then all you need is an event
handler with Handles MyLinkButton.Click (VB syntax).
If it's part of a bigger control, like a datalist or a datagrid, then you
need to handle MyDataList.ItemCommand, which gets the click event for all
buttons within that container. If you have multiple buttons, then in that
event handler you want to check conditionally for which specific button was
clicked. Easiest way is when you add the linkbutton to the control, set the
CommandName property--i.e. MyButton1, MButton2, etc.--then in your event
handler you can do a case statement on e.item.CommandName to get the button.
You can also set CommandArgument, which lets you pass an additional argument
to your handler when the button is clicked.
 
Ah, getting it from a user control makes it a little hairier. The cleanest way I know of is for your user control to raise an event when one of its buttons is clicked (might as well call it Click a la the framework). Then register an event handler for MyUserControl.Click in your hosting page. Presuming your user control has multiple link buttons, then in the EventArgs of the event you raise you'll want to identify the particular button that was clicked, along with any other arguments you need to go with it. In the event handler on the page, you'll parse the eventargs and then do whatever you're going to do. If you have other user controls on the page and they need to know about the event, you can register event handlers for them too. If I can add any more detail please let me know. HTH

Bill Bor

----- Andreas Klemt wrote: ----

Hello Bill

thanks for your answer
I am looking for a way how I can see in a Page_Load which LinkButton i
clicke
from other UserControls. Is there a way to see it in Page_Load

Thanks for any help!
Kind Regard
Andrea


Bill Borg said:
I might need more detail behind your question, but in short it depends o where your linkbutton is
need to handle MyDataList.ItemCommand, which gets the click event for al
buttons within that container. If you have multiple buttons, then in tha
event handler you want to check conditionally for which specific button wa
clicked. Easiest way is when you add the linkbutton to the control, set th
CommandName property--i.e. MyButton1, MButton2, etc.--then in your even
handler you can do a case statement on e.item.CommandName to get the button
You can also set CommandArgument, which lets you pass an additional argumen
to your handler when the button is clicked
 
Back
Top