Adding javascript client-side funtionality to a Button webcontrol

J

Jørn A

I just learned how to add client-side javascript funtionality to a Button
Web control by using the Attributes.Add method at run-time.
myButton.Attributes.Add("onClick", "return confirm('Are you sure about
this?');")

But the problem arises when I want to add similar conditional funtionality
to buttons i a datagrid:
I have a datagrid in one of my pages where I want one column with buttons. I
want these buttons to open a new page in a new browser window, passing
different querystring parameters based on values from the record for the
specific datagrid-row.
The client-side attribute for the button in a specific datagrid row should
be something like:

onClick="window.open('theotherpage.asp?id=thisrecordsid&customer=thisrecords
customer

Can anyone show an example of how to accomplish this (preferably in VB.Net)?
 
J

Jørn A

That's OK, but you did not use a WebControl in your example... I need to use
a WebControl for the other funtionality in my page. A standard input HTML
tag won't do.

I thought of using a HTMLControl (input) instead of a WebControl, but then I
had a new problem with ASPNET HTML-encoding the content of my onClick event.

Any more suggestions anyone?

-Jørn A.
 
B

Benyamin Maengkom

Private Sub ItemCreated(ByVal Sender As Object, ByVal E As
DataGridItemEventArgs) Handles Datagrid1.ItemCreated
Select Case E.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.SelectedItem
Dim drv As DataRowView = E.Item.DataItem
Dim theimagebutton As ImageButton
theimagebutton = E.Item.FindControl("theimagebutton") 'note
: theimagebutton is the name of control too...
theimagebutton.Attributes.Add("onclick",
"window.open('theotherpage.asp?id= & drv.Item("thisrecordsid") &
"&customer=" & drv.Item("thisrecordscustomer") & "');")
End Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top