Solved

Gridview1_RowCommand Causes HTTP Error 400

Posted on 2014-03-20
2
479 Views
Last Modified: 2014-03-20
I am in the process of converting an old version of an asp.net application to newer controls. I am trying to use a gridview and I have it populated from the SQL Server. I have several asp:button fields for "Edit" and "Delete". When I click either of the buttons the code behind works but when it completes the procedure the postback causes an HTTP Error 400 - Bad Request.

I commented out the lines...I know this is fired with a post back but not sure why the page does not return to it previous display.

               <asp:Panel id ='referenceLevelLabels' runat="server" CssClass="panel">
                    <asp:GridView ID="referenceLevelLabel" runat="server" AutoGenerateColumns="False" CssClass="gridview">

                        <AlternatingRowStyle BackColor="LightSteelBlue" />
                        <Columns>
                            <asp:TemplateField HeaderText="Action">
                                <itemtemplate>
                                    <asp:Button ID="refEdit" Text="Edit" CommandName="Edit" runat="server" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" />
                                    <asp:Button ID="refDelete" Text="Delete" CommandName="Delete" runat="server" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" />
                                </itemtemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="referenceLevelLabel" HeaderText="Label"  SortExpression="referenceLevelLabel" >
                                <ItemStyle BackColor="BlanchedAlmond" />
                            </asp:BoundField>
                            <asp:BoundField DataField="referenceLevelStatus" HeaderText="Status" />
                            <asp:BoundField DataField="isDefaultLabel" HeaderText="Is Default" />
                        </Columns>
                    </asp:GridView>                    
                </asp:Panel>

Open in new window


    Private Sub referenceLevelLabel_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles referenceLevelLabel.RowCommand
        ' If multiple ButtonField column fields are used, use the
        ' CommandName property to determine which button was clicked.
        If e.CommandName = "Edit" Then

            '' Convert the row index stored in the CommandArgument
            '' property to an Integer.
            'Dim index As Integer = Convert.ToInt32(e.CommandArgument)

            '' Get the last name of the selected author from the appropriate
            '' cell in the GridView control.
            'Dim selectedRow As GridViewRow = referenceLevelLabel.Rows(index)
            'Dim labelCell As TableCell = selectedRow.Cells(referenceColumns.label)
            'Dim reference As String = labelCell.Text

            ''lblmessage.Text = "You selected " & reference & "."
            ''lblmessage.Visible = True

        End If
    End Sub

Open in new window

0
Comment
Question by:Brandon_Campbell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Accepted Solution

by:
Brandon_Campbell earned 0 total points
ID: 39943358
I discovered that the commandname name has reserved words. The Edit and Delete must be something like EditMe or DeleteMe if you want to handle the click event of the button in the rowcommand procedure.

Once this was changed then it did the postback without any hiccups or errors.
0
 

Author Closing Comment

by:Brandon_Campbell
ID: 39943364
I saw this on a different solution within EE.
Change the attribute commandName from Edit to EditMe or Delete to DeleteMe.
The Edit and Delete have specific methods for handling these type of events if you leave the names as Edit or Delete.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question