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

  • 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.CssClass = this.CssPrefix + "btnCSS";
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
1 Solution
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

>>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?

SammyAuthor Commented:
the controls enabled state is set to false in a another method call
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.

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.

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
public override void DataBind()
//Ommitted code      
               base.DataBind ();
Well done :)
Closed, 500 points refunded.
Community Support Moderator

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