Is it possible to trigger another onclientclick button?
I have a modal popup that has a targetId for a hidden button. I want the popup to appear when a button in the grid is clicked, but this button is programmed behind code and so the targetID will be invalid ...
So, I wanted to try to set the gridview button onclientclick so that it is the onclientclickevent of this hidden button. Is this possible, or should I follow this path.
this 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
a source to share
I am assuming you are using web forms. If yes, then yes, it is very possible. Follow these steps.
-
Create javascript function in page
function openModal(btnId){ btn = document.getElementById(btnId); btn.click(); // this should fire the click even of the button }
-
on the grid button add an onclientclick event:
gridButton.OnClientClick = String.Format("openModal('{0}');", modalButton.ClientId))
This will set the client id of the button that launches the modal into a javascript function. If you need to fill the modal with other data, you must do so in this function as well.
Are you using ASP.NET AJAX Control Toolkit? Or something different? This assumes a set of tools.
Also, you have made the button visible to be hidden, but not Visible=False
on the server side property , as this will not show the button. To hide it you will need to use the client side propertystyle="display:none"
This link can help: http://forums.asp.net/t/1066506.aspx
a source to share
This is possible, it requires you to disable the "DoPostback" buttons.
Try to learn the method Page.ClientScript.GetPostBackClientHyperlink
.
Alternatively you can use javascript and event .click()
, but I think this limits you to IE as a browser, but not sure about that.
It will look like
javascript:document.getElementById('clientSideID').click();
a source to share