Solved

Gridview1_RowCommand Causes HTTP Error 400

Posted on 2014-03-20
2
474 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
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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP Classic - Load test 2 45
Field that has HTML displays the code instead of the text in html 16 64
ASP SQL Syntax Duplicate Key 7 93
If-Then-Else ASP problem 6 50
A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

861 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

23 Experts available now in Live!

Get 1:1 Help Now