CheckBox CheckedChanged event without AutoPostBack = True

1.5k Views Asked by At

I added checkbox control to the GridView column dynamically. On each GridView_RowBound() event, checkbox is being added to the column. Also defined, CheckBox_CheckedChanged event in the RowBound() event as below,

Protected Sub GridviewChildItem_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

    If e.Row.RowType = DataControlRowType.DataRow AndAlso Not String.IsNullOrEmpty(CRMSignCond) Then
        Dim lbValue As Label = DirectCast(e.Row.Cells(5).FindControl("lbValue"), Label)
        e.Row.Cells(5).Attributes.Add("onmousemove", "Show('" + lbValue.Text + "')")
        e.Row.Cells(5).Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor;Hide();")
    End If

    AddTemplateControls(Nothing, e)


End Sub
Private Sub AddTemplateControls(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    Dim cbTargetSign As New CheckBox
    Dim rbConsolidate As New RadioButtonList
    Dim tbSignGrp As New TextBox

    cbTargetSign.ID = "chkSelect"
    cbTargetSign.AutoPostBack = False
    cbTargetSign.Checked = True
    rbConsolidate.ID = "rbConsolidate"
    tbSignGrp.ID = "tbSigningGroup"
    tbSignGrp.Width = 25
    If Not e.Row.RowIndex = -1 Then
        e.Row.Cells(6).Controls.Add(cbTargetSign)
        e.Row.Cells(4).Controls.Add(tbSignGrp)
        e.Row.Cells(7).Controls.Add(rbConsolidate)
    End If
    rbConsolidate.RepeatDirection = RepeatDirection.Horizontal
    rbConsolidate.Items.Add("Yes")
    rbConsolidate.Items.Add("No")
    rbConsolidate.Items(1).Selected = CBool(True)
    If cbTargetSign.Checked Then
        rbConsolidate.Enabled = False
    End If
    **AddHandler cbTargetSign.CheckedChanged, AddressOf cbTargetSign_CheckedChanged**
End Sub

'Checkbox- CheckedChanged event.

Public Sub cbTargetSign_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)

End Sub

Every time, when i check the checkbox in the grid, checkedChanged event doesn't trigger. Anyone guide me how to resolve this ?

Note: I don't want to set AutoPostBack of checkbox to TRUE since it reloads the entire grid with default values.

enter image description here

1

There are 1 best solutions below

0
On

If you don't want to set AutoPostBack of checkbox to TRUE since it reloads the entire grid with default values, you will try set AutoPostBack="True" and:

`<`asp:UpdatePanel ID="itemPanel" runat="server" UpdateMode="Conditional"`>`<br/>
                `<`ContentTemplate`>`<br/>
                   //your controls<br/>
               `<`/ContentTemplate`>`<br/>
`<`/asp:UpdatePanel`>`