troubleshooting Question

ASP.net GridView button not working

Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland asked on
ASP.NETVisual Basic.NET
4 Comments1 Solution78 ViewsLast Modified:
Hi

I have the following ASP.net GridView button. On other pages it work but for some reason it isn't firing on this one page
I have included my markup and VB.net below

           <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False">
                    
                     
                     <Columns>
             
                 <asp:TemplateField HeaderText="?" ControlStyle-Forecolor ="Gray">
                    <ItemTemplate>
                        <asp:Button ID="ButtonQuestion" OnClientClick="showLoading();" runat="server" 
                        CommandName="btnQuestion" 
                        CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>"
                        Text="?" />
                    </ItemTemplate>
                    <ControlStyle ForeColor="#468499" />
                </asp:TemplateField>

            ElseIf (e.CommandName = "btnQuestion") Then

                ' Retrieve the row index stored in the CommandArgument property.
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                ' Retrieve the row that contains the button 
                ' from the Rows collection.
                Dim row As GridViewRow = GridView1.Rows(index)

                If IsPostBack Then

                    Dim lblItemID As Label = CType(row.FindControl("lblItemID"), Label)
                    Dim lblOrderQty As Label = CType(row.FindControl("lblOrderQty"), Label)
                    Dim lblDescription As Label = CType(row.FindControl("lblDescription"), Label)
                    Dim lblRandsPerTon As Label = CType(row.FindControl("lblUnitPrice"), Label)
                    Dim lblTotalPrice As Label = CType(row.FindControl("lblTotalPrice"), Label)
                    Dim lblCanOffer As Label = CType(row.FindControl("lblCanOffer"), Label)
                    Dim lblSellerUsername As Label = CType(row.FindControl("lblSellerUsername"), Label)

                    Dim oMessageHeader As String = "Offer Enquiry on Stock ID " & lblItemID.Text
                    oMessageHeader = oMessageHeader & " R/Ton " & lblRandsPerTon.Text
                    oMessageHeader = oMessageHeader & " Quantity " & lblOrderQty.Text
                    oMessageHeader = oMessageHeader & " Total Price " & lblTotalPrice.Text
                    Dim S As String
                    S = "Stock Detail:"
                    S = S & vbCrLf
                    S = S & vbCrLf & "Item ID: " & lblItemID.Text
                    S = S & vbCrLf & "Order Quantity: " & lblOrderQty.Text
                    S = S & vbCrLf & "Rands per Ton " & lblRandsPerTon.Text
                    S = S & vbCrLf & "Total Price " & lblTotalPrice.Text
                    'NOTE REPLACE BREAK IN LINE BELOW BECAUSE IT CAN"T BE EMAILED....
                    S = S & vbCrLf & "Description: " & Replace(lblDescription.Text, "<br/>", vbCrLf)

                    Session("oMessageStockDetail") = S

                    Session("oMessage_BuyerUsername") = oUsername
                    Session("oMessage_SellerUsername") = lblSellerUsername.Text

                    Session("oMessageFromEmail") = oUsername
                    Session("oMessageToEmail") = lblSellerUsername.Text

                    'REDIRECT TO MESSAGE WEB PAGE
                    Page.ClientScript.RegisterStartupScript(Me.[GetType](), "OpenWindow", "window.open('Message.aspx','_newtab');", True)

                    'Response.Redirect("Message.aspx") 'Same browser page

                End If
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros