I am trying to create an event handler for my link labels. What I want to do is when someone clicks the link then it should open the link in a new browser. But the problem I am having is that I dont know how to add event handler for link labels.
This is what I am trying to do, but I dont know what I am missing. Also I am not sure if " LinkClickedEventArgs" is right or am I suppose to add something else. - Private Sub addCommandHandler()
-
Dim ctrl As Control
-
For Each ctrl In Me.Controls
-
If TypeOf (ctrl) Is Label Then
-
AddHandler ctrl.Click, AddressOf link_Clicked
-
End If
-
Next
-
End Sub
-
-
Public Sub link_Clicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkClickedEventArgs)
-
-
End Sub
6 1160
I am trying to create an event handler for my link labels. What I want to do is when someone clicks the link then it should open the link in a new browser. But the problem I am having is that I dont know how to add event handler for link labels.
This is what I am trying to do, but I dont know what I am missing. Also I am not sure if "LinkClickedEventArgs" is right or am I suppose to add something else. - Private Sub addCommandHandler()
-
Dim ctrl As Control
-
For Each ctrl In Me.Controls
-
If TypeOf (ctrl) Is Label Then
-
AddHandler ctrl.Click, AddressOf link_Clicked
-
End If
-
Next
-
End Sub
-
-
Public Sub link_Clicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkClickedEventArgs)
-
-
End Sub
Edit:
I see what you're trying to do. Let me think about it.
???
Click is a standard event. You don't have to add one yourself, you just have to implement it.
Can you tell me why you're adding event handlers like this?
Well,
I have 12 linklabels and I want to do smart programming. So instead of doing something - Private Sub LinkLabel12_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel12.LinkClicked
-
System.Diagnostics.Process.Start("http://" + LinkLabel12.Text)
-
End Sub
for 12 labels, I want to add an event handler which will automatically figure out which link is clicked and display it in the browser. I was able to add right event handlers, but now the problem is that I dont get the data of the link, for example in code below I cannot get the link value which can be www.yahoo.ca or something else - Private Sub addCommandHandler()
-
Dim ctrl As Control
-
For Each ctrl In Me.Controls
-
If TypeOf (ctrl) Is LinkLabel Then
-
AddHandler CType(ctrl, LinkLabel).LinkClicked, AddressOf EventHandler
-
End If
-
Next
-
End Sub
-
-
Private Sub EventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
-
Dim target As String = CType(e.Link.LinkData, String)
-
MsgBox(target)
-
End Sub
Well if you want to have them open links in new windows, you're going to need to use javascript, not server-side code.
So you would go do something like: -
Dim ctrl As Control
-
For Each ctrl In Me.Controls
-
If TypeOf (ctrl) Is LinkLabel Then
-
ctrl.Attributes.Add("onclick","SomeJavaScriptFunctionToOpenNewWindow("&"The url you want maybe"&");")
-
End If
-
Next
-
Then add a javascript function to your page that takes in a url and opens another window with the link.
Well if you want to have them open links in new windows, you're going to need to use javascript, not server-side code.
So you would go do something like: -
Dim ctrl As Control
-
For Each ctrl In Me.Controls
-
If TypeOf (ctrl) Is LinkLabel Then
-
ctrl.Attributes.Add("onclick","SomeJavaScriptFunctionToOpenNewWindow("&"The url you want maybe"&");")
-
End If
-
Next
-
Then add a javascript function to your page that takes in a url and opens another window with the link.
I don't think he's doing asp.
I don't think he's doing asp.
Good point, well then the post prior to mine appeared to have the correct functionality, but I hate sifting through vb "code" so I can't be sure why it didn't work.
Although I would probably have gone with using the sender object o for finding out what was clicked.
Good point, well then the post prior to mine appeared to have the correct functionality, but I hate sifting through vb "code" so I can't be sure why it didn't work.
Although I would probably have gone with using the sender object o for finding out what was clicked.
Guys, I have found out myself. As I mentioned in my previous posts that I am kinda out from development since a while, thats why I am finding hard to pick it up again. Anyways, here is the working code. - Private Sub addCommandHandler()
-
Dim ctrl As Control
-
For Each ctrl In Me.Controls
-
If TypeOf (ctrl) Is LinkLabel Then
-
AddHandler CType(ctrl, LinkLabel).LinkClicked, AddressOf EventHandler
-
End If
-
Next
-
End Sub
-
-
Private Sub EventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
-
System.Diagnostics.Process.Start("http://" & CType(sender, LinkLabel).Text)
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Christopher W. Douglas |
last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a
method that handles several events, such as closing a form and changing the
visible status of a form. I have some code...
|
by: Mark |
last post by:
Hi,
I'm looking for some ideas on how to build a very simple Event processing
framework in my C++ app. Here is a quick background ...
I'm building a multithreaded app in C++ (on Linux) that...
|
by: Waqas Pitafi |
last post by:
Hi,
3rd day is already gone without any solution.
My problem is, I have a Windows Server 2003 sp1 machine as my development
platform having NTFS filesystem. Other notable components installed...
|
by: Ivan |
last post by:
I am used to VB6 and am not sure how to do this in
Vstudio .NET. I have a main form which calls other
forms. I want to disable that main form while other ones
are called. I tried hiding it and...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |