Avatar of pmodiano1
pmodiano1
 asked on

How to perform both a server and client side events with an ASP.NET ImageButton

Hi,

I have an ImageButton inside a repeater.  When the repeater loads these buttons are visible and are in the same position as a flash media player, which is not visible.  The repeater's ItemDatabound looks like this:

    Protected Sub catlist_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles catlist.ItemDataBound
        Dim ListenButton As ImageButton
        Dim FlashPlayer As Panel
        ListenButton = CType(e.Item.FindControl("ListenButton"), ImageButton)
        FlashPlayer = CType(e.Item.FindControl("FlashPlayer"), Panel)
        If (Not ListenButton Is Nothing) Then
            ListenButton.Attributes.Add("onclick", "document.getElementById('" & FlashPlayer.ClientID & "').style.visibility = 'visible'; document.getElementById('" & ListenButton.ClientID & "').style.visibility = 'hidden'; return false;")
        End If
    End Sub

Open in new window


Now, a new requirement has been introduced that requires me to perform a server side event as well but because the OnClick attribute is being added dynamically, I cannot seem to find a way to trigger a server side event while at the same time maintaining the current client side functionality.

Any ideas?

Thanks,

Paul.
ASP.NETJavaScript

Avatar of undefined
Last Comment
Gorkem Yuksel

8/22/2022 - Mon
Paul Jackson

try putting the client side functionality on the onclientclick attribute like :
ListenButton.Attributes.Add("onclientclick", "document.getElementById('" & FlashPlayer.ClientID & "').style.visibility = 'visible'; document.getElementById('" & ListenButton.ClientID & "').style.visibility = 'hidden'; return false;")

then add your server side event to onclick.
ASKER CERTIFIED SOLUTION
Gorkem Yuksel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Gorkem Yuksel

Sorry.. the Button1 reference should be ListenButton
pmodiano1

ASKER
Thanks to both of you.  I like gyuksel's solution.

I forgot to mention one more thing: On the click event, I need to access a dataitem from that row's to write it to disk If I send the button click to ListenButton_Click routine, how will I be able to access a dataitem for that row?

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Gorkem Yuksel

Hi,

You can access the parent control of the "sender" object (which is the button) which should give you the row index of the dataitem.  You can also add a Tag value to the button when creating it as well and add the row index into that if you want to make it easier.

ListenButton.Tag = e.Item.Index


Cheers,

G.
pmodiano1

ASKER
Thanks so much!
Gorkem Yuksel

Anytime.  Glad I could help! :)

Cheers,

G.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.