Solved

Gridview1_RowCommand Causes HTTP Error 400

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

821 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