Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

control loses state when page renders to browser

Control inherits from DataGrid
in the ItemCreated event this code generate a table containing buttons and adds them to the table

if (this.ExtraButtonCount > 0)
                        {
                              System.Web.UI.WebControls.TableRow extraButtonRow = new TableRow();
                              System.Web.UI.WebControls.TableCell buttonCell = new TableCell();
                              buttonCell.HorizontalAlign = HorizontalAlign.Right;
                              buttonCell.ColumnSpan = 3;
                              extraButtonRow.Controls.Add(buttonCell);
                              extraButtonRow.CssClass = this.CssPrefix + "btnCSS";
                              buttonCell.Controls.Add(this.CreateButtonTable());                              
                              pagerTable.Rows.Add(extraButtonRow);
                        }
When the application in debug mode I can see all buttons in correct state the ones are set to enabled=false are disabled but when the application renders to the browser all buttons are enabled again
the prerender event does not have any code related to any of the buttons
it seems like I am missing something simple here but I can not seem to find it
0
Sammy
Asked:
Sammy
1 Solution
 
RedKelvinCommented:
make sure you are making use of ispostback

If Not IsPostBack Then
' not post back, set stuff up
end if

otherwise you may be resetting values unintentionally.

without all the code, it is really hard to determine the problem

RedK
0
 
RejojohnyCommented:
>>When the application in debug mode I can see all buttons in correct state the ones are set to enabled=false are disabled
where are setting them to enabled = false in your code above .. is it set within the cssclass?

Rejo
0
 
SammyAuthor Commented:
the controls enabled state is set to false in a another method call
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
jinn_hnnlCommented:
I think Kelvin is right. You might wanna check the use of IsPostBack. Since your buttons are generated dynamically. After post back, they aren't included in Controls hierarhical anymore.

Make sure the adding procedure is invoked in the PageLoad method.

Jinni
0
 
SammyAuthor Commented:
Found out what was the problem
 CreateChildControls() was overwritten and the method which creates the buttons was Not added to the call which causes the control to keeps on clearing the control collections whenever any of the control is bound to a datafield
solution was to add the method call as follow

protected override void CreateChildControls()
            {
                  base.CreateChildControls ();
                     //Ommited code
                       this.CreateButtonTable();
            }
public override void DataBind()
      {
//Ommitted code      
               base.DataBind ();
              this.CreateButtonTable();
         }
0
 
jinn_hnnlCommented:
Well done :)
0
 
modus_operandiCommented:
Closed, 500 points refunded.
modus_operandi
Community Support Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now