Event Handling in VB.Net WebForms
-
I got the following code (C#) from a VSj article and dont know how I would translate it to VB.Net, can anyone help? What we are doing is adding a series of LinkButtons to a table on the page, assigning the CommandName and Text programmatically: --- System.WebControls.LinkButton btn = new LinkButton(); // assign various properties of the button... btn.Click += new new System.EventHandler(btnClick); --- the above code presumably assigns the event to a single event handler that will then be used to work out which button fired the event and act according to the CommandName But I dont know how to do similar in VB.Net. Thanks for any help... Rohan.:wtf:
-
I got the following code (C#) from a VSj article and dont know how I would translate it to VB.Net, can anyone help? What we are doing is adding a series of LinkButtons to a table on the page, assigning the CommandName and Text programmatically: --- System.WebControls.LinkButton btn = new LinkButton(); // assign various properties of the button... btn.Click += new new System.EventHandler(btnClick); --- the above code presumably assigns the event to a single event handler that will then be used to work out which button fired the event and act according to the CommandName But I dont know how to do similar in VB.Net. Thanks for any help... Rohan.:wtf:
i'm not too sure with what the code is trying to do( haven't really gotten into C# yet :( ) but if it's event handling you want, this might be what you're looking for:
Friend WithEvents Btn as new System.Web.UI.WebControls.LinkButton() Private Sub btnClick(_arguments_) handles btn.click _coding_ End Sub
I hope that's what you're loking for!:) Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark Twain -
i'm not too sure with what the code is trying to do( haven't really gotten into C# yet :( ) but if it's event handling you want, this might be what you're looking for:
Friend WithEvents Btn as new System.Web.UI.WebControls.LinkButton() Private Sub btnClick(_arguments_) handles btn.click _coding_ End Sub
I hope that's what you're loking for!:) Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark TwainThe point of this is that I am programattically adding buttons at runtime so I cannot have an individual event handler for each one as I dont know how many there will be. However, the code translator at: http://www.aspalliance.com/aldotnet/examples/translate.aspx has helped me find the solution: btn.Click += new System.EventHandler(btnClick) would translate to: AddHandler btn.Click, AddressOf btnClick Thanks, Rohan :)
-
The point of this is that I am programattically adding buttons at runtime so I cannot have an individual event handler for each one as I dont know how many there will be. However, the code translator at: http://www.aspalliance.com/aldotnet/examples/translate.aspx has helped me find the solution: btn.Click += new System.EventHandler(btnClick) would translate to: AddHandler btn.Click, AddressOf btnClick Thanks, Rohan :)
No, Thank You!! I learned something new today:-O Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
Get your facts first, and then you can distort them as much as you please Mark Twain