We help IT Professionals succeed at work.

control loses state when page renders to browser

Sammy
Sammy asked
on
248 Views
Last Modified: 2010-04-15
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
Comment
Watch Question

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
>>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
CERTIFIED EXPERT

Author

Commented:
the controls enabled state is set to false in a another method call
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
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Well done :)
CERTIFIED EXPERT

Commented:
Closed, 500 points refunded.
modus_operandi
Community Support Moderator

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.