Strange problem of Dynamic Checkbox

Discussion in 'ASP .Net' started by savvy, Nov 15, 2005.

  1. savvy

    savvy Guest

    I'm comparing two strings and trying to check a dynamic checkbox when
    its true on pageload , but i dont know why i'm not able to do that on
    page load, when i click some other links and come back to this page
    then the required checkbox will be checked. I'm not able to figure out
    where is the problem. Sorry about the long code
    Any help will be greatly appreciated

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    {
    get_servc();
    }
    }


    override protected void OnInit(EventArgs e)
    {
    InitializeComponent();
    base.OnInit(e);
    if (Page.IsPostBack)
    {
    Session.Timeout=120;
    _checkboxes = (ArrayList) Session["CheckBoxArray"];
    }
    else
    {
    _checkboxes = new ArrayList();
    get_servc();
    }

    foreach(CheckBox c1 in _checkboxes)
    Panel1.Controls.Add(c1);
    }


    public void get_servc()
    {
    strcatgy = Convert.ToString(Session["Category"]);
    string temp = strcatgy;
    int xPos = 20;
    int yPos= 335;
    int count=0;
    objcmd = new SqlCommand("SelectDynControls", objConn);
    objcmd.CommandType = CommandType.StoredProcedure;
    objConn.Open();
    objRdr=objcmd.ExecuteReader();
    while(objRdr.Read())
    {
    CheckBox c1 = new CheckBox();
    c1.ID="chk" + _checkboxes.Count.ToString();
    c1.AutoPostBack=true;
    c1.Visible=true;
    c1.Text = Convert.ToString(objRdr["CbName"]);


    if(c1.Text == temp)
    {
    c1.Checked=true; // this is the part which is not working
    }

    c1.Style.Add("DISPLAY", "BLOCK");
    if((count % 6)==0)
    {
    yPos +=30;
    xPos =20;
    }
    c1.Style.Add("POSITION", "absolute");
    c1.Style.Add("TOP", Convert.ToString(yPos));
    c1.Style.Add("LEFT", Convert.ToString(xPos));
    _checkboxes.Add(c1);
    Panel1.Controls.Add(c1);
    xPos += 120;
    count += 1;
    }
    objRdr.Close();
    objConn.Close();
    yPos = yPos + 50;
    xPos = 275;
    }
     
    savvy, Nov 15, 2005
    #1
    1. Advertising

  2. savvy

    savvy Guest

    Actually the code had no problem
    As I was creating the dynamic controls prior to page load. we have to
    call method get_servc() again as shown in my code below
    and now its working
    hope this will be of some help to the people who stuck with the same
    problem


    private void dl_Edit(object source,
    System.Web.UI.WebControls.DataListCommandEventArgs e)
    {
    strcatgy =((Label)e.Item.FindControl("lblcategory")).Text;
    Session["Category"]= strcatgy;
    get_servc();
    ............
    ...........
    ............
    }
     
    savvy, Nov 15, 2005
    #2
    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:
    0
    Views:
    529
    tshad
    Apr 15, 2005
  2. Dev

    Strange Problem: Templated checkbox column

    Dev, May 5, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    707
  3. pizzy
    Replies:
    0
    Views:
    167
    pizzy
    Mar 23, 2005
  4. pizzy
    Replies:
    5
    Views:
    384
    pizzy
    Apr 12, 2005
  5. morellik

    Check checkbox strange problem

    morellik, Dec 27, 2006, in forum: Javascript
    Replies:
    9
    Views:
    111
    Bart Van der Donck
    Jan 3, 2007
Loading...

Share This Page