Link to home
Start Free TrialLog in
Avatar of sticar
sticar

asked on

Use OnClick event from another button link

I have an image and a hyperlink button.  I want the image to go to the same link as the hyperlink.

Sub Mylink_Click ( attirbutes) Handles mylink_click
    Server.Transfer(mylink.aspx)
End Sub

Sub Myimage_Click ( attributes) Handles myimage_click
    Mylink_Click()                   'Doesn't work
End Sub

Isn't there a better way?
Avatar of AlexFM
AlexFM

Sub Myimage_Click ( attributes) Handles myimage_click
    mylink.PerformClick()          ' assuming that button has mylink name
End Sub
Hi there...
use an "ImageButton"... instead of "Image"...

-Baan
Avatar of sticar

ASKER

It actually is an ImageButton, sorry.
try

Sub Mylink_Click ( attirbutes) Handles mylink_click, myimage_click
    Server.Transfer(mylink.aspx)
End Sub
Avatar of sticar

ASKER

rfgkey... I tried that one before and it said the paramaters were different for myimage_click
ASKER CERTIFIED SOLUTION
Avatar of rfgkev
rfgkev

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sticar

ASKER

I won't be able to try this for about 5 more hours.  I'll let you know.  Thanks for all the input.
sorry.. I was out for lunch...

ok.. if you want to execute the evant handler of the link from the Imgae Button.. do this...

Mylink_Click ( attirbutes)
inside the ImageButton_click. Parameter for this will be (sender, e)... no need to go for server.transfer.

-Baan
Avatar of sticar

ASKER

I'm not understanding what you're saying Baan.  ?
ok... you want this... right?
<<
Sub Mylink_Click ( attirbutes) Handles mylink_click
    Server.Transfer(mylink.aspx)
End Sub

Sub Myimage_Click ( attributes) Handles myimage_click
    Mylink_Click()                   'Doesn't work
End Sub
>>

change Myimage_click...
Sub Myimage_Click ( attributes) Handles myimage_click
    Mylink_Click(attributes)                   'Will work (Attribute=> Sender,e)
End Sub

-Baan
Avatar of sticar

ASKER

That is what I actually have, it starts redirecting it but I think it gets messed up somehow because in my link I have a raise event too...
 
Sub mylink_click (attributes)
   Raise.Myevent( sender, e)
   Server.Transfer(mylink.aspx)
End Sub
hmmm... well.. did you try    Response.Redirect("mylink.aspx")   ? might work

-Baan
The reason why
Sub Mylink_Click ( attirbutes) Handles mylink_click
    Server.Transfer(mylink.aspx)
End Sub

Sub Myimage_Click ( attributes) Handles myimage_click
    Mylink_Click()                   'Doesn't work
End Sub

Because when a click is called as an event ( that is when you click stuff ) certain arguments are passed automatically to the the event handler hence if you manually call the click event it will not work. I would suggest the best solution to be what  rfgkev mentioned above..

Sub Mylink_Click ( attirbutes) Handles mylink_click
    DoTransfer()
End Sub

Sub Myimage_Click ( attributes) Handles myimage_click
    DoTransfer()
End Sub

Private Sub DoTransfer
    Server.Transfer(mylink.aspx)
End Sub

hth

--yatharth