oncheckedchanged event is not firing everytime on checkbox

Discussion in 'ASP .Net Web Controls' started by Hitesh Jain, Oct 14, 2004.

  1. Hitesh Jain

    Hitesh Jain Guest

    Hi,
    I have a checkbox control inside a datalist control's item template and in
    the html i am associating the event handler with the oncheckedchanged event
    for the checkbox like the following:
    OnCheckedChanged="OnCheckedItem"
    now when i am running the ASP.NET application and say at runtime 3 checkbox
    gets generated based on the data from my database, and if i checked the first
    checkbox the event is firing but now when i uncheck the same checkbox the
    event is not firing.
    Can anybody help me to get a resolution or workaround for this problem.
    If you need any further details then let me know so that i can provide the
    same.
    Thanks
    Hitesh
     
    Hitesh Jain, Oct 14, 2004
    #1
    1. Advertising

  2. What you've written isn't exactly explaning the real work done behind the
    scenes. Is checking unchecking done at once on the client side or is there a
    postback inbetween?

    Anyway. I can answer on both.
    A. Twice checking/unchecking on the client without postback
    I think this is pretty obviews why there is no checked change event here,
    because to the server the unchecked "went out" and uncheked "came in".
    Sometimes this behavior should fire server events i.e. multipage selects and
    one global selection - when global selection is clicked all selects on all
    pages (visible page + other) should be selected. One checkbox is deselected
    on the current page, global should uncheck, but other pages must stay
    checked. This is normal behavior, and you have to do this with another
    server control (must have more than two states), best with hidden field
    check uncheck other pages.

    B. First check, then postback and uncheck and postback.
    The problem that you're having is ViewState. Let's examine the process:

    1. you get a checkbox on the client and check it
    2. postback.
    3. your checkboxes are regenerated on the server and change events are
    executed and everything goes back to the client with viewstate info
    supplied.
    4. you uncheck the checkbox on the client
    5. postback
    6. step by step
    - parse the aspx
    - on init fires
    - views state loads the state of the page as it was sent to the client
    on previus request
    - postback data changes values to new ones and prepares change and
    action events as well
    - on load fires
    - change events fire
    - action event(s) fire
    - no need for me to go any furter. after this pre render, saving view
    state, render and unload.

    ok so where seems to be the problem? Your page gets parsed. No checkboxes
    yet while you create them dynamicly. Ok. on init fires, last page view state
    loads and doesn't update your checkboxes, so they stay unchecked. When
    change events should fire, your checkboxes don't fire them, while postback
    data wasn't passed to them.

    the reason for this behavior is that you create your checkboxes too late as
    in page load event.

    I just hope I didn't mess things up this time, while already 11 hours
    straight at work. :( Going home now. Good night.

    --
    RobertK
    { Clever? No just smart. }

    "Hitesh Jain" <Hitesh > wrote in message
    news:...
    > Hi,
    > I have a checkbox control inside a datalist control's item template and in
    > the html i am associating the event handler with the oncheckedchanged

    event
    > for the checkbox like the following:
    > OnCheckedChanged="OnCheckedItem"
    > now when i am running the ASP.NET application and say at runtime 3

    checkbox
    > gets generated based on the data from my database, and if i checked the

    first
    > checkbox the event is firing but now when i uncheck the same checkbox the
    > event is not firing.
    > Can anybody help me to get a resolution or workaround for this problem.
    > If you need any further details then let me know so that i can provide the
    > same.
    > Thanks
    > Hitesh
     
    Robert Koritnik, Oct 14, 2004
    #2
    1. Advertising

  3. Hitesh Jain

    Hitesh Guest

    Hi Robert,
    Thanks for you indepth analysis of the problem and yes there is a postback
    between checking and unchecking, i had made the autopostback property of the
    checkbox to true, but now the question with us is how to solve the problem
    can you help me on this futher...?
    Thanks a bunch for the description.

    "Robert Koritnik" wrote:

    > What you've written isn't exactly explaning the real work done behind the
    > scenes. Is checking unchecking done at once on the client side or is there a
    > postback inbetween?
    >
    > Anyway. I can answer on both.
    > A. Twice checking/unchecking on the client without postback
    > I think this is pretty obviews why there is no checked change event here,
    > because to the server the unchecked "went out" and uncheked "came in".
    > Sometimes this behavior should fire server events i.e. multipage selects and
    > one global selection - when global selection is clicked all selects on all
    > pages (visible page + other) should be selected. One checkbox is deselected
    > on the current page, global should uncheck, but other pages must stay
    > checked. This is normal behavior, and you have to do this with another
    > server control (must have more than two states), best with hidden field
    > check uncheck other pages.
    >
    > B. First check, then postback and uncheck and postback.
    > The problem that you're having is ViewState. Let's examine the process:
    >
    > 1. you get a checkbox on the client and check it
    > 2. postback.
    > 3. your checkboxes are regenerated on the server and change events are
    > executed and everything goes back to the client with viewstate info
    > supplied.
    > 4. you uncheck the checkbox on the client
    > 5. postback
    > 6. step by step
    > - parse the aspx
    > - on init fires
    > - views state loads the state of the page as it was sent to the client
    > on previus request
    > - postback data changes values to new ones and prepares change and
    > action events as well
    > - on load fires
    > - change events fire
    > - action event(s) fire
    > - no need for me to go any furter. after this pre render, saving view
    > state, render and unload.
    >
    > ok so where seems to be the problem? Your page gets parsed. No checkboxes
    > yet while you create them dynamicly. Ok. on init fires, last page view state
    > loads and doesn't update your checkboxes, so they stay unchecked. When
    > change events should fire, your checkboxes don't fire them, while postback
    > data wasn't passed to them.
    >
    > the reason for this behavior is that you create your checkboxes too late as
    > in page load event.
    >
    > I just hope I didn't mess things up this time, while already 11 hours
    > straight at work. :( Going home now. Good night.
    >
    > --
    > RobertK
    > { Clever? No just smart. }
    >
    > "Hitesh Jain" <Hitesh > wrote in message
    > news:...
    > > Hi,
    > > I have a checkbox control inside a datalist control's item template and in
    > > the html i am associating the event handler with the oncheckedchanged

    > event
    > > for the checkbox like the following:
    > > OnCheckedChanged="OnCheckedItem"
    > > now when i am running the ASP.NET application and say at runtime 3

    > checkbox
    > > gets generated based on the data from my database, and if i checked the

    > first
    > > checkbox the event is firing but now when i uncheck the same checkbox the
    > > event is not firing.
    > > Can anybody help me to get a resolution or workaround for this problem.
    > > If you need any further details then let me know so that i can provide the
    > > same.
    > > Thanks
    > > Hitesh

    >
    >
    >
     
    Hitesh, Oct 14, 2004
    #3
  4. Hitesh Jain

    Hitesh Guest

    Hi Robert,
    Success! great thanks from me, with the help of your knowldge i could able
    to manage the things. The trick is, i did the coding in prerender event for
    the processing of checkbox's changes which initially i was doing in the event
    handler for the oncheckedchanged event of the checkbox. so now things are
    working and i am able to manage the checking and unchecking of child check
    boxes based on the checked state of the parent check box, only drawback with
    this is the code is executed always as prerender fires on every postback
    whether its because of the checkbox or because of any other control. But in
    my case the page is only having check boxes so celebrating the success!
    Thanks a lot for all the geniuses who have spent their time on this problem,
    and special thanks to Robert.

    Cheers!
    Hitesh

    "Hitesh" wrote:

    > Hi Robert,
    > Thanks for you indepth analysis of the problem and yes there is a postback
    > between checking and unchecking, i had made the autopostback property of the
    > checkbox to true, but now the question with us is how to solve the problem
    > can you help me on this futher...?
    > Thanks a bunch for the description.
    >
    > "Robert Koritnik" wrote:
    >
    > > What you've written isn't exactly explaning the real work done behind the
    > > scenes. Is checking unchecking done at once on the client side or is there a
    > > postback inbetween?
    > >
    > > Anyway. I can answer on both.
    > > A. Twice checking/unchecking on the client without postback
    > > I think this is pretty obviews why there is no checked change event here,
    > > because to the server the unchecked "went out" and uncheked "came in".
    > > Sometimes this behavior should fire server events i.e. multipage selects and
    > > one global selection - when global selection is clicked all selects on all
    > > pages (visible page + other) should be selected. One checkbox is deselected
    > > on the current page, global should uncheck, but other pages must stay
    > > checked. This is normal behavior, and you have to do this with another
    > > server control (must have more than two states), best with hidden field
    > > check uncheck other pages.
    > >
    > > B. First check, then postback and uncheck and postback.
    > > The problem that you're having is ViewState. Let's examine the process:
    > >
    > > 1. you get a checkbox on the client and check it
    > > 2. postback.
    > > 3. your checkboxes are regenerated on the server and change events are
    > > executed and everything goes back to the client with viewstate info
    > > supplied.
    > > 4. you uncheck the checkbox on the client
    > > 5. postback
    > > 6. step by step
    > > - parse the aspx
    > > - on init fires
    > > - views state loads the state of the page as it was sent to the client
    > > on previus request
    > > - postback data changes values to new ones and prepares change and
    > > action events as well
    > > - on load fires
    > > - change events fire
    > > - action event(s) fire
    > > - no need for me to go any furter. after this pre render, saving view
    > > state, render and unload.
    > >
    > > ok so where seems to be the problem? Your page gets parsed. No checkboxes
    > > yet while you create them dynamicly. Ok. on init fires, last page view state
    > > loads and doesn't update your checkboxes, so they stay unchecked. When
    > > change events should fire, your checkboxes don't fire them, while postback
    > > data wasn't passed to them.
    > >
    > > the reason for this behavior is that you create your checkboxes too late as
    > > in page load event.
    > >
    > > I just hope I didn't mess things up this time, while already 11 hours
    > > straight at work. :( Going home now. Good night.
    > >
    > > --
    > > RobertK
    > > { Clever? No just smart. }
    > >
    > > "Hitesh Jain" <Hitesh > wrote in message
    > > news:...
    > > > Hi,
    > > > I have a checkbox control inside a datalist control's item template and in
    > > > the html i am associating the event handler with the oncheckedchanged

    > > event
    > > > for the checkbox like the following:
    > > > OnCheckedChanged="OnCheckedItem"
    > > > now when i am running the ASP.NET application and say at runtime 3

    > > checkbox
    > > > gets generated based on the data from my database, and if i checked the

    > > first
    > > > checkbox the event is firing but now when i uncheck the same checkbox the
    > > > event is not firing.
    > > > Can anybody help me to get a resolution or workaround for this problem.
    > > > If you need any further details then let me know so that i can provide the
    > > > same.
    > > > Thanks
    > > > Hitesh

    > >
    > >
    > >
     
    Hitesh, Oct 15, 2004
    #4
  5. You didn't have to put things in PreRender, which is more like a
    workarround. One thing is that you should have your checkboxes prepared as
    late as in OnInit. If this would be a custom server control,
    CreateChildControls would be the best one to go for. That way ViewState will
    be preserved as well as PostBack processing and all events.

    --
    RobertK
    { Clever? No just smart. }

    "Hitesh" <> wrote in message
    news:...
    > Hi Robert,
    > Success! great thanks from me, with the help of your knowldge i could able
    > to manage the things. The trick is, i did the coding in prerender event

    for
    > the processing of checkbox's changes which initially i was doing in the

    event
    > handler for the oncheckedchanged event of the checkbox. so now things are
    > working and i am able to manage the checking and unchecking of child check
    > boxes based on the checked state of the parent check box, only drawback

    with
    > this is the code is executed always as prerender fires on every postback
    > whether its because of the checkbox or because of any other control. But

    in
    > my case the page is only having check boxes so celebrating the success!
    > Thanks a lot for all the geniuses who have spent their time on this

    problem,
    > and special thanks to Robert.
    >
    > Cheers!
    > Hitesh
    >
    > "Hitesh" wrote:
    >
    > > Hi Robert,
    > > Thanks for you indepth analysis of the problem and yes there is a

    postback
    > > between checking and unchecking, i had made the autopostback property of

    the
    > > checkbox to true, but now the question with us is how to solve the

    problem
    > > can you help me on this futher...?
    > > Thanks a bunch for the description.
    > >
    > > "Robert Koritnik" wrote:
    > >
    > > > What you've written isn't exactly explaning the real work done behind

    the
    > > > scenes. Is checking unchecking done at once on the client side or is

    there a
    > > > postback inbetween?
    > > >
    > > > Anyway. I can answer on both.
    > > > A. Twice checking/unchecking on the client without postback
    > > > I think this is pretty obviews why there is no checked change event

    here,
    > > > because to the server the unchecked "went out" and uncheked "came in".
    > > > Sometimes this behavior should fire server events i.e. multipage

    selects and
    > > > one global selection - when global selection is clicked all selects on

    all
    > > > pages (visible page + other) should be selected. One checkbox is

    deselected
    > > > on the current page, global should uncheck, but other pages must stay
    > > > checked. This is normal behavior, and you have to do this with another
    > > > server control (must have more than two states), best with hidden

    field
    > > > check uncheck other pages.
    > > >
    > > > B. First check, then postback and uncheck and postback.
    > > > The problem that you're having is ViewState. Let's examine the

    process:
    > > >
    > > > 1. you get a checkbox on the client and check it
    > > > 2. postback.
    > > > 3. your checkboxes are regenerated on the server and change events are
    > > > executed and everything goes back to the client with viewstate info
    > > > supplied.
    > > > 4. you uncheck the checkbox on the client
    > > > 5. postback
    > > > 6. step by step
    > > > - parse the aspx
    > > > - on init fires
    > > > - views state loads the state of the page as it was sent to the

    client
    > > > on previus request
    > > > - postback data changes values to new ones and prepares change and
    > > > action events as well
    > > > - on load fires
    > > > - change events fire
    > > > - action event(s) fire
    > > > - no need for me to go any furter. after this pre render, saving

    view
    > > > state, render and unload.
    > > >
    > > > ok so where seems to be the problem? Your page gets parsed. No

    checkboxes
    > > > yet while you create them dynamicly. Ok. on init fires, last page view

    state
    > > > loads and doesn't update your checkboxes, so they stay unchecked. When
    > > > change events should fire, your checkboxes don't fire them, while

    postback
    > > > data wasn't passed to them.
    > > >
    > > > the reason for this behavior is that you create your checkboxes too

    late as
    > > > in page load event.
    > > >
    > > > I just hope I didn't mess things up this time, while already 11 hours
    > > > straight at work. :( Going home now. Good night.
    > > >
    > > > --
    > > > RobertK
    > > > { Clever? No just smart. }
    > > >
    > > > "Hitesh Jain" <Hitesh > wrote in message
    > > > news:...
    > > > > Hi,
    > > > > I have a checkbox control inside a datalist control's item template

    and in
    > > > > the html i am associating the event handler with the

    oncheckedchanged
    > > > event
    > > > > for the checkbox like the following:
    > > > > OnCheckedChanged="OnCheckedItem"
    > > > > now when i am running the ASP.NET application and say at runtime 3
    > > > checkbox
    > > > > gets generated based on the data from my database, and if i checked

    the
    > > > first
    > > > > checkbox the event is firing but now when i uncheck the same

    checkbox the
    > > > > event is not firing.
    > > > > Can anybody help me to get a resolution or workaround for this

    problem.
    > > > > If you need any further details then let me know so that i can

    provide the
    > > > > same.
    > > > > Thanks
    > > > > Hitesh
    > > >
    > > >
    > > >
     
    Robert Koritnik, Oct 15, 2004
    #5
    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. Homa
    Replies:
    3
    Views:
    15,007
    nchavan
    Jul 23, 2009
  2. Maziar Aflatoun

    asp checkbox checking for OnCheckedChanged value

    Maziar Aflatoun, Sep 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    23,407
    radu_m
    Dec 29, 2008
  3. Replies:
    1
    Views:
    5,144
    =?Utf-8?B?UmFq?=
    Jul 5, 2006
  4. Danielle
    Replies:
    1
    Views:
    2,823
    Munna
    Jun 8, 2008
  5. arby

    Checkbox in DataGrid Not Firing OnCheckedChanged events.

    arby, Jan 30, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    553
    Alvin Bruney [MVP]
    Jan 31, 2004
Loading...

Share This Page