Responding to Imagebutton click in DataList

Discussion in 'ASP .Net Web Controls' started by J 2 the B, Jul 24, 2003.

  1. J 2 the B

    J 2 the B Guest

    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.
     
    J 2 the B, Jul 24, 2003
    #1
    1. Advertising

  2. 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"><strong>Budget
    >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"> </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"> </td>
    > <td width="100" class="Text"> </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"> </td>
    > <td width="100" class="Text"> </td>
    > <td width="100" class="Text"> </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"> </td>
    > <td width="100" class="Text"> </td>
    > <td width="100" class="Text"> </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"> </td>
    > <td width="100" class="Text"> </td>
    > <td width="100" class="Text"> </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"> </td>
    > <td width="100" class="Text"> </td>
    > <td width="100" class="Text"> </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"> </td>
    > <td width="100" class="Text"> </td>
    > <td width="100" class="Text"> </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.
    >.
    >
     
    Ravikanth[MVP], Jul 25, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon

    Click not responding

    Jon, Jan 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    356
    Ken Cox [Microsoft MVP]
    Jan 15, 2004
  2. Steve Lloyd
    Replies:
    1
    Views:
    704
    Rick Spiewak
    May 26, 2004
  3. Dave
    Replies:
    0
    Views:
    322
  4. Nevyn Twyll
    Replies:
    8
    Views:
    1,874
  5. James Tsao
    Replies:
    0
    Views:
    266
    James Tsao
    Oct 25, 2004
Loading...

Share This Page