Solved

Gridview1_RowCommand Causes HTTP Error 400

Posted on 2014-03-20
2
468 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
  • 2
2 Comments
 

Accepted Solution

by:
Brandon_Campbell earned 0 total points
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches users how to migrate an existing Wordpress website to a new domain.
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now