Hi, I am creating a forum which has 2 linkbuttons in each gridview row that shows each posts. One is edit and the other is reply. I intended to have 2 different actions when the button is clicked. The problem is, I can only click either of them once. Subsequent press wont work.

So, this is my ASP.NET code

<asp:TemplateField>
                <ItemTemplate>
                    <div style="text-align: justify">
                        <asp:LinkButton ID="btnReply" commandargument = <%# container.DisplayIndex%> commandname ="Reply" runat="server">Reply</asp:LinkButton>
                        <br />
                        <asp:LinkButton ID="btnEdit" commandargument = <%# container.DisplayIndex%> commandname ="Reply" runat="server">Edit</asp:LinkButton>
                    </div>
                </ItemTemplate>

VB code

Protected Sub gvPosts_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvPosts.RowCommand
        gvPosts.EditIndex = -1
        Dim RowNo = Convert.ToInt32(e.CommandArgument)
        Dim lblPostID As Label
        If dvThreadPost.Table Is Nothing Then
            Response.Redirect(Request.Url.AbsoluteUri) 'Need to refresh the page
        End If

        For i = 0 To dvThreadPost.Table.Rows.Count - 1
            lblPostID = CType(gvPosts.Rows(RowNo).FindControl("lblPostID"), Label)
            If lblPostID.Text = dvThreadPost.Table.Rows(i)("PostID") Then
                'Set the Textbox value using this grid / data view
                If e.CommandName = "Edit" Then
                    mce.Value = dvThreadPost.Table.Rows(i)("Content")
                ElseIf e.CommandName = "Reply" Then
                    mce.Value = "<blockquote>--------------------- Originally posted by: " & dvThreadPost.Table.Rows(i)("Name") & "--------------------------------------<br />" & dvThreadPost.Table.Rows(i)("Content") & "<br /> -----------------------------------------------------------</blockquote><br />"
                End If
                ScriptManager.RegisterStartupScript(Me.Page, Me.Page.[GetType](), mce.ClientID, "callInt" + mce.ClientID & "();", True)
                Exit For
            End If
        Next

    End Sub

    Protected Sub gvPosts_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvPosts.RowEditing
        'For edit post to use
    End Sub

    Protected Sub gvPosts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvPosts.SelectedIndexChanged
        'For reply post use
    End Sub

The problem is, for example, I firstly click on the Reply button, and then I changed my mind to use edit button (Maybe press wrong button in the first place?), the debugger still say

e.CommandName = "Reply"

instead of Edit. So what should I do to allow it to be more flexible?

Opps, there was an stupid error in the code (The command name got wrong). However, it does not work in UpdatePanel. (Error 500 unknown error)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.