I have a modal popup that has a targetId to a hidden button. I want the popup to occur when a button in a grid is clicked but that button is programmed behind the code and therefore the targetId would be invalid...
So I wanted to attempt to set the gridview's button's onclientclick event to be the onclientclickevent of that hidden button. Is this possible or should I be going about this another way.
here is how i created the grid button
If Not IsPostBack Then
Dim field As New TemplateField
field.HeaderText = "Sub Departments"
Dim col As DataControlField = field
GridView1.Columns.Add(col)
For i As Integer = 0 To GridView1.Rows.Count - 1
Dim btnview As New ImageButton
btnview.ImageUrl = "\images\icons\xp_ico_search_24x24.gif"
GridView1.Rows(i).Cells(3).Controls.Add(btnview)
Next
End If
I am assuming you are using web forms. If so then yes, it it very possible. Do the following.
Create a javascript function on the page
function openModal(btnId){
btn = document.getElementById(btnId);
btn.click(); // this should fire the click even of the button
}
on the grid button add the onclientclick event:
gridButton.OnClientClick = String.Format("openModal('{0}');", modalButton.ClientId))
This will set the client Id of the button that trigers the modal window into the javascript function. If you need to populate the modal window with other data, you should do it in this function as well.
Are you using the ASP.Net AJAX Control Toolkit? Or something else? This assumes the toolkit.
Also, you have set the visibility of the button to hidden, but do not the the Visible=False
property on the server side, as this will not render the button. To hide it you will need to use the client side property style="display:none"
This link may help: http://forums.asp.net/t/1066506.aspx