Programmatic CheckBox Event Not Firing

Discussion in 'ASP .Net' started by DotNetJunkies User, Oct 21, 2004.

  1. Hi,

    I have a checkbox control programmatically created for each row in the datagrid but CheckedChanged event not firing when state of the checkbox changes.

    I use the following code to instantiate ItemTemplate with checkbox contructor:

    public class TemplateObject : ITemplate {
    public void InstantiateIn(Control objContainer) {
    CheckBox objCheckBox = new CheckBox();
    objCheckBox.ID = "Item";
    objCheckBox.CheckedChanged +=new EventHandler(objCheckBox_CheckedChanged);
    objContainer.Controls.Add(objCheckBox);
    }

    public void objCheckBox_CheckedChanged(object sender, EventArgs e) {
    CheckBox objCheckBox = (CheckBox)sender;
    if(objCheckBox.Checked) {
    //Do Something
    }
    }
    }

    Any advice much appreciated.


    Andrew



    ---
    Posted using Wimdows.net NntpNews Component -

    Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
     
    DotNetJunkies User, Oct 21, 2004
    #1
    1. Advertising

  2. DotNetJunkies User

    Cirrosi Guest

    You don't have set autopostback=true;

    "DotNetJunkies User" <> ha scritto nel
    messaggio news:%23$...
    > Hi,
    >
    > I have a checkbox control programmatically created for each row in the
    > datagrid but CheckedChanged event not firing when state of the checkbox
    > changes.
    >
    > I use the following code to instantiate ItemTemplate with checkbox
    > contructor:
    >
    > public class TemplateObject : ITemplate {
    > public void InstantiateIn(Control objContainer) {
    > CheckBox objCheckBox = new CheckBox();
    > objCheckBox.ID = "Item";
    > objCheckBox.CheckedChanged +=new
    > EventHandler(objCheckBox_CheckedChanged);
    > objContainer.Controls.Add(objCheckBox);
    > }
    >
    > public void objCheckBox_CheckedChanged(object sender, EventArgs e) {
    > CheckBox objCheckBox = (CheckBox)sender;
    > if(objCheckBox.Checked) {
    > //Do Something
    > }
    > }
    > }
    >
    > Any advice much appreciated.
    >
    >
    > Andrew
    >
    >
    >
    > ---
    > Posted using Wimdows.net NntpNews Component -
    >
    > Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup
    > engine supports Post Alerts, Ratings, and Searching.
     
    Cirrosi, Oct 21, 2004
    #2
    1. Advertising

  3. Not sure, but did you trying setting Autopostback to true?

    "DotNetJunkies User" <> wrote in message
    news:%23$...
    > Hi,
    >
    > I have a checkbox control programmatically created for each row in the
    > datagrid but CheckedChanged event not firing when state of the checkbox
    > changes.
    >
    > I use the following code to instantiate ItemTemplate with checkbox
    > contructor:
    >
    > public class TemplateObject : ITemplate {
    > public void InstantiateIn(Control objContainer) {
    > CheckBox objCheckBox = new CheckBox();
    > objCheckBox.ID = "Item";
    > objCheckBox.CheckedChanged +=new
    > EventHandler(objCheckBox_CheckedChanged);
    > objContainer.Controls.Add(objCheckBox);
    > }
    >
    > public void objCheckBox_CheckedChanged(object sender, EventArgs e) {
    > CheckBox objCheckBox = (CheckBox)sender;
    > if(objCheckBox.Checked) {
    > //Do Something
    > }
    > }
    > }
    >
    > Any advice much appreciated.
    >
    >
    > Andrew
    >
    >
    >
    > ---
    > Posted using Wimdows.net NntpNews Component -
    >
    > Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup
    > engine supports Post Alerts, Ratings, and Searching.
     
    Ken Cox [Microsoft MVP], Oct 21, 2004
    #3
  4. Thank you chaps, been puzzled by such a simple property that I hav completely
    forgotten.

    Andrew

    "DotNetJunkies User" wrote:

    > Hi,
    >
    > I have a checkbox control programmatically created for each row in the datagrid but CheckedChanged event not firing when state of the checkbox changes.
    >
    > I use the following code to instantiate ItemTemplate with checkbox contructor:
    >
    > public class TemplateObject : ITemplate {
    > public void InstantiateIn(Control objContainer) {
    > CheckBox objCheckBox = new CheckBox();
    > objCheckBox.ID = "Item";
    > objCheckBox.CheckedChanged +=new EventHandler(objCheckBox_CheckedChanged);
    > objContainer.Controls.Add(objCheckBox);
    > }
    >
    > public void objCheckBox_CheckedChanged(object sender, EventArgs e) {
    > CheckBox objCheckBox = (CheckBox)sender;
    > if(objCheckBox.Checked) {
    > //Do Something
    > }
    > }
    > }
    >
    > Any advice much appreciated.
    >
    >
    > Andrew
    >
    >
    >
    > ---
    > Posted using Wimdows.net NntpNews Component -
    >
    > Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
    >
     
    =?Utf-8?B?QW5kcmV3?=, Oct 21, 2004
    #4
    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. tshad
    Replies:
    5
    Views:
    5,988
    Joaquin Corchero
    Mar 15, 2005
  2. Replies:
    2
    Views:
    8,627
    tdavisjr
    Oct 17, 2005
  3. Replies:
    1
    Views:
    1,061
    nahid
    Jul 12, 2007
  4. shiv

    CheckBox Changed Event Not Firing in DataGrid

    shiv, Jun 18, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    534
  5. runner7

    programmatic firing of keydown event

    runner7, Sep 8, 2006, in forum: Javascript
    Replies:
    9
    Views:
    336
    runner7
    Sep 11, 2006
Loading...

Share This Page