c# - Show Hide using Javascript on a control, inside a ASCX control in a gridview. (ASP.NET + Javascript) -
i have written web usercontrol (ascx). inside, there panel want show/hide on click of hyperlink inside usercontrol.
normally, easy doing (the onclick attribute added hyperlink on prerender):
var paneltoshow = document.getelementbyid('<%=panelinvoicehasbeencreated.clientid %>'); if (paneltohide != null) { paneltohide.style.display = 'none'; }
but because ascx control held within gridview, above assess controls (of there many in gridview) name 'panelinvoicehasbeencreated'. time work when there 1 row in gridview. currently, existing code, if click hyperlink in row, shows/hides panel in bottom row of gridview!
therefore, question how actual, unique id need show/hide on correct control in correct row??????
thanks in advance.
you can @ rowdatabound event of gridview
write below code @ gridview rowdatabound event
var usercontrol1=(usercontrol)e.item.findcontrol("usercontrol1"); var hyperlink1=(hyperlink)usercontrol1.findcontrol("hyperlink1"); var panelinvoicehasbeencreated=(panel)usercontrol1.findcontrol("panelinvoicehasbeencreated"); hyperlink1..attributes.add("onclick", "javascript:return showhidepanel('"+ panelinvoicehasbeencreated.clientid +"')");
and java script function @ aspx page should this
<script type="text/javascript"> function showhidepanel(panelid) { var paneltoshow = document.getelementbyid('panelid'); if (paneltohide != null) { paneltohide.style.display = 'none'; } return false; } </script>
Comments
Post a Comment