Event Hander for OnCheckChanged Event for a CheckBox Template Field

Discussion in 'ASP .Net' started by David Johnston, Apr 27, 2011.

  1. First, let me say I am relatively new to ASP.NET ... most .NET
    experience is with C# (Winforms).

    Now, I have a web page with a gridview that contains a checkbox
    control in a template field (see definition below):

    <asp:TemplateField
    ConvertEmptyStringToNull="False"
    HeaderStyle-CssClass="header"
    HeaderText="Select">
    <ItemTemplate>
    <asp:CheckBox ID="chkSelectAgent"
    runat="server"
    OnCheckedChanged="chkSelectAgent_CheckChanged" />
    </ItemTemplate>
    </asp:TemplateField>

    On the same page, I have a list box control. When the check box on a
    given row is clicked, I want to populate a row in the list box. My
    event handler is listed below:

    Public Sub chkSelectAgent_CheckChanged(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles chkSelectAgent.CheckedChanged
    Dim sAgentId As String
    Dim sFirst As String
    Dim sLast As String
    Dim chkSelectedAgent As CheckBox
    Dim gvrSelectedAgent As GridViewRow

    If TypeOf sender Is CheckBox Then
    chkSelectedAgent = DirectCast(sender, CheckBox)
    If chkSelectedAgent.Checked Then
    gvrSelectedAgent =
    DirectCast(chkSelectedAgent.Parent.Parent, GridViewRow)
    sAgentId = gvrSelectedAgent.Cells(1).Text
    sFirst = gvrSelectedAgent.Cells(2).Text
    sLast = gvrSelectedAgent.Cells(3).Text
    lbSelectedAgents.Items.Add(sFirst + " " + sLast + " (Agent
    ID: " + sAgentId + ")")
    End If
    End If
    End Sub

    When I set a breakpoint in the event handler, it does hit the
    breakpoint, but only when I go to another page, not when I click in a
    check box. Do I need to set AutoPostBack="true" for the checkbox
    column? When I tried that, my page no longer renders. I'm guessing
    that is because I haven't handled the postback in the Page_Load
    subroutine.

    So, I have two questions:

    1) Why isn't the event hander being fired when I click the checkbox?
    2) If AutoPostBack is needed, why doesn't anything get rendered on the
    postback (not even labels and text boxes)?

    I have googled this like crazy and haven't found a definitive answer.
    If you have any good informational links, I not only want to solve the
    problem, but also to learn in the process. Thanks in advance for any
    help you can provide.
    David Johnston, Apr 27, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob
    Replies:
    1
    Views:
    12,005
    Louis Dascoulias
    Jul 9, 2003
  2. James  Norton-Jones
    Replies:
    4
    Views:
    4,272
    James Zhuo
    Aug 25, 2003
  3. Vittorix

    chechbox OnCheckChanged doesn't work!

    Vittorix, Dec 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    373
    Vittorix
    Dec 19, 2007
  4. Chris Fink

    Event Hander Question

    Chris Fink, Dec 8, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    126
    John Saunders
    Dec 9, 2004
  5. Joey Pang
    Replies:
    4
    Views:
    485
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page