Home > DeveloperSection > Forums > check box not working properly at page load in asp.net
E E Cummings
E E Cummings

Total Post:26

Points:182
Posted on    July-15-2013 8:40 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 3029  View(s)
Rate this:
Hi Developers!

I have got problem with check-box to enable corresponding control next to it. My Requirement is at the page load we want to disable the all textboxes and dropdownlists by using checkbox if the check-box is checked the control next to that check-box will be enabled for that i have done like this....

at page load

i have written like this

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ChckOrdType.Checked = false;
            ChkPlntPric.Checked = false;
            ChkExcluBro.Checked = false;
            ......
            .....
        }

and then in checkbox check changed event i have written like this

    protected void ChckOrdType_CheckChanged(object sender, EventArgs e)
    {
        if (ChckOrdType.Checked)           
            ddlOrdType.Enabled = true;
        else 
            ddlOrdType.Enabled = false;            
    }
 
    protected void chkPlntPric_CheckChanged(object sender, EventArgs e)
    {
        if (ChkPlntPric.Checked)
            ddlPlntPric.Enabled = true;
        else
            ddlPlntPric.Enabled = false;
    }
 
    protected void chkExcluBro_CheckChanged(object sender, EventArgs e)
    {
        if (ChkExcluBro.Checked)
            ddlExcluBroker.Enabled = true;
        else
            ddlExcluBroker.Enabled = false;       
    }

but results is like this ... I am getting checkbox not checked and control next to it is enabled...But this not what i want

My results is if the check-box is not checked the control next to it is disabled would any one pls help on this...

Thanks In advance......



shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    July-15-2013 11:54 PM

Hello E E Cumming!

This is because you have just wrote ONLY to uncheck the checkboxes in the pageload and not to disable the controls behind the checkbox; If thats needed, then your snippet in the pageload should be:

if (!Page.IsPostBack)

{

  ChckOrdType.Checked = false;

  ChkPlntPric.Checked = false;

  ChkExcluBro.Checked = false;

  ......

  .....

  ddlOrdType.Enabled = false;

  ddlPlntPric.Enabled = false;

  ddlExcluBroker.Enabled = false; 

  .........

}

or

if (!Page.IsPostBack)

{

  ChckOrdType.Checked = false;

  ChkPlntPric.Checked = false;

  ChkExcluBro.Checked = false;

  ......

  .....

 

  ChckOrdType_CheckChanged(sender,e);

  chkPlntPric_CheckChanged(sender,e);

  chkExcluBro_CheckChanged(sender,e);

  ...

}

i hope this code is helpful for you



Don't want to miss updates? Please click the below button!

Follow MindStick