?
Solved

Gridview1_RowCommand Causes HTTP Error 400

Posted on 2014-03-20
2
Medium Priority
?
482 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
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…
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

752 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