Link to home
Start Free TrialLog in
Avatar of kmoloney
kmoloneyFlag for United States of America

asked on

Code-Behind out of a Web Page Button Click...

Hello there...

I have an aspx page with a multiview.  I have a Data List in one of these views, and at the bottom of each datalist section there is are two buttons, one of which, when pressed, needs to execute some fairly complex VB.NET code and go to a third view.

Because the button is inside a view, it doesn't expose itself through vb intellisense.

How can I configure the app so that when I press on this button it will execute CODE-BEHIND VB, rather than having to get it to perform script?

Here's the code for the datalist:

            <asp:DataList ID="DataList1" runat="server" DataSourceID="ODS_Progress" Style="position: relative" DataKeyField="progID" Width="100%">
               
                <ItemTemplate>
                <table width=98% style="font-size:small">
                    <tr>
                    <td width=30%>
                    Comment ID:
                    </td>
                    <td>
                    <asp:Label ID="progIDLabel" runat="server" Text='<%# Eval("progID") %>'></asp:Label>
                    </td>
                    </tr>
                   
                    <tr>
                    <td>
                    Work Order ID:
                    </td>
                    <td>
                    <asp:Label ID="woIDLabel" runat="server" Text='<%# Eval("woID") %>'></asp:Label>
                    </td>
                    </tr>
                   
                    <tr>
                    <td>
                    Comment By:
                    </td>
                    <td>
                    <asp:Label ID="progNoteByLabel" runat="server" Text='<%# Eval("progNoteBy") %>'>
                    </asp:Label>
                    </td>
                    </tr>
                   
                    <tr>
                    <td>
                    Comment Date:
                    </td>
                    <td>
                    <asp:Label ID="progNoteDateLabel" runat="server" Text='<%# Eval("progNoteDate") %>'>
                    </asp:Label>
                    </td>
                    </tr>
                   
                    <tr>
                    <td>
                    Publish?
                    </td>
                    <td>
                    <asp:Label ID="progPublishLabel" runat="server" Text='<%# Eval("progPublish") %>'>
                    </asp:Label>
                    </td>
                    </tr>
                   
                   
                   
                    <tr>
                    <td>
                    Comment / Question:
                    </td>
                    <td>
                    <asp:Label ID="progNoteLabel" runat="server" Text='<%# Eval("progNote") %>'></asp:Label>
                    </td>
                    </tr>
                    <hr />
                </table>
                    <asp:Button ID="btnBack" runat="server" Text="Back to List" />&nbsp;&nbsp;
                    <asp:Button ID="btnRespond" runat="server" Text="Respond" />
                </ItemTemplate>
               
               <AlternatingItemStyle BackColor=#FFFFD0 />
                             
            </asp:DataList>
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

1) Define an event handler in the HTML designer OnClick="Button1_Click".

2) Attach an event handler to the button in the ItemDataBound event handler for each item.

Bob
Avatar of kmoloney

ASKER

I get #1...can you be a little clearer (or, I guess, give me an example) of #2?  I haven't worked with event handlers that much.
Actually, I don't think I need the ItemDataBound or the OnClick.

1.  I put CommandName="select" in the <asp:button ... > declaration that is embedded in the ItemTemplate

2.  Going to Design View of the .aspx page, I double-click on the datalist control (datalist1).  It automatically generates the Datalist1.SelectedIndexChanged subroutine.

3.  I call Datalist1.DataBind() to "select" the item.

4.  I now have access to any of the values inside this selected item by CTYPE'ing the specific item in it's controls collection, e.g.,

dim lbl as label
dim obj as object
dim intNumber as integer

obj=Me.DataList1.SelectedItem.Controls.Item(5)  'whatever the number of the item I wat to fetch
lbl=Ctype(obj, label)
intNumber=Convert.ToInt32(lbl.text)

intNumber can be a shared variable, so I can use it after I change the view.

Any simpler methods?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial