Responding to Imagebutton click in DataList

J

J 2 the B

I have two imagebuttons (A & B) on my page, and I am trying to create
events that when I click on image A, it becomes invisible, and Image B
becomes visible.

I can get it all to work fine when I'm not using it inside a DataList,
but once I wrap a DataList around the table, I get errors like: "Name
'Button1' is not declared.

Here is my html code that shows the Datalist, table, and imagebutton
info:
<code>
<table width="550" border="0">
<!-- BEGIN DataList dlCommEstate0 -->
<asp:DataList ID="dlCommEstate0" runat="server" gridlines="both">
<itemtemplate>
<tr>
<td colspan="5" nowrap> <p align="center"><strong>Budget
Report</strong></p></td>
</tr>
<tr>
<td colspan="2" rowspan="3" nowrap>&nbsp;</td>
<td colspan="3" class="Text">&nbsp;</td>
</tr>
<tr>
<td width="100" class="Text"><div
align="center"><strong>Budget</strong></div></td>
<td width="100" class="Text"><div
align="center"><strong>Actuals</strong></div></td>
<td width="100" class="Text"><div
align="center"><strong>Variance</strong></div></td>
</tr>
<tr>
<td width="100" class="Text"><div
align="center"><strong>Period</strong></div></td>
<td width="100" class="Text"><div
align="center"><strong>Period</strong></div></td>
<td width="100" class="Text"><div
align="center"><strong>Period</strong></div></td>
</tr>
<tr>
<td width="20" nowrap><div align="center">
<asp:ImageButton id=Button1 ImageUrl="/vista/images/expand.gif"
width="15" height="15" BorderWidth="2px"
onclick="ImageButton1_OnClick" runat="server" visible="true" />
<asp:ImageButton id=Button2 ImageUrl="/vista/images/collapse.gif"
width="15" height="15" BorderWidth="2px"
onclick="ImageButton2_OnClick" runat="server" visible="false" />
</td>
<td width="200" nowrap class="update-fields"><div
align="right"><strong>Rental Revenues</strong></div></td>
<td width="100" class="Text"></td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
</tr>
<tr>
<td width="20" nowrap><div align="center">&nbsp;</div></td>
<td width="200" nowrap class="Text"><div align="right">Third Party
Rent</div></td>
<td width="100" class="Text"><asp:Label id=Label1 runat=server
/></td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
</tr>
<asp:panel id="pnlRevenue" visible="true">
<tr>
<td width="20" nowrap><div align="center"></div></td>
<td nowrap class="Text"><div align="right">Ad Hording</div></td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
</tr>
<tr>
<td width="20" nowrap><div align="center"></div></td>
<td width="200" nowrap class="Text"><div
align="right">Aerials</div></td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
</tr>
<tr>
<td width="20" nowrap><div align="center"></div></td>
<td width="200" nowrap class="Text"><div
align="right">Parking</div></td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
</tr>
<tr>
<td width="20" nowrap><div align="center"></div></td>
<td width="200" nowrap class="Text"><div
align="right">SubStations</div></td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
</tr>
</asp:panel>
<tr>
<td width="20" nowrap><div align="center"></div></td>
<td width="200" nowrap class="Text"><div align="right"><strong>Sub
Totals</strong></div></td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
<td width="100" class="Text">&nbsp;</td>
</tr>
</itemtemplate>
</asp:DataList>
</table>
<!-- END DataList dlCommEstate0 -->
</code>

And here is the onClick code foreach of the imagebuttons:
<code>
'Event for Expand button click. Show Collapse button, hide Expand
button
Sub ImageButton1_OnClick(sender As Object, e As ImageClickEventArgs)
Button1.Visible = "False"
Button2.Visible="True"
End Sub

'Event for Collapse button click. Show Expand button, hide Collapse
button
Sub ImageButton2_OnClick(sender As Object, e As ImageClickEventArgs)
Button2.Visible = "False"
Button1.Visible="True"
End Sub
</code>

The error I get is: "Name 'Button1' is not declared" in the
ImageButton1_OnClick event. So I guess my question is, how do I
declare those imagebuttons in order to use them in the datalist??

TIA.
 
R

Ravikanth[MVP]

Hi

You need to dynamically attach Image Click Event to the
Image buttons which are there in DataList.


Ravikanth

-----Original Message-----
I have two imagebuttons (A & B) on my page, and I am trying to create
events that when I click on image A, it becomes invisible, and Image B
becomes visible.

I can get it all to work fine when I'm not using it inside a DataList,
but once I wrap a DataList around the table, I get errors like: "Name
'Button1' is not declared.

Here is my html code that shows the Datalist, table, and imagebutton
info:
<code>
<table width="550" border="0">
<!-- BEGIN DataList dlCommEstate0 --

<asp:DataList ID="dlCommEstate0" runat="server" gridlines="both">
<itemtemplate>
<tr>
<td colspan="5" nowrap> <p
align="center"> said:
Report</strong></p></td>
</tr>
<tr>
<td colspan="2" rowspan="3" nowrap> </td>
<td colspan="3" class="Text"> </td>
</tr>
<tr>
<td width="100" class="Text"><div
align="center"><strong>Budget</strong></div></td>
<td width="100" class="Text"><div
align="center"><strong>Actuals</strong></div></td>
<td width="100" class="Text"><div
align="center"><strong>Variance</strong></div></td>
</tr>
<tr>
<td width="100" class="Text"><div
align="center"><strong>Period</strong></div></td>
<td width="100" class="Text"><div
align="center"><strong>Period</strong></div></td>
<td width="100" class="Text"><div
align="center"><strong>Period</strong></div></td>
</tr>
<tr>
<td width="20" nowrap><div align="center">
<asp:ImageButton id=Button1 ImageUrl="/vista/images/expand.gif"
width="15" height="15" BorderWidth="2px"
onclick="ImageButton1_OnClick" runat="server" visible="true" />
<asp:ImageButton id=Button2 ImageUrl="/vista/images/collapse.gif"
width="15" height="15" BorderWidth="2px"
onclick="ImageButton2_OnClick" runat="server" visible="false" />
</td>
<td width="200" nowrap class="update-fields"><div
align="right"><strong>Rental Revenues</strong></div></td>
<td width="100" class="Text"></td>
<td width="100" class="Text"> </td>
<td width="100" class="Text"> </td>
</tr>
<tr>
<td width="20" nowrap><div
align="center"> said:
<td width="200" nowrap class="Text"><div align="right">Third Party
Rent</div></td>
<td width="100" class="Text"><asp:Label id=Label1 runat=server
/></td>
<td width="100" class="Text"> </td>
<td width="100" class="Text"> </td>
</tr>
<asp:panel id="pnlRevenue" visible="true">
<tr>
<td width="20" nowrap><div
align="center"> said:
<td nowrap class="Text"><div align="right">Ad
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top