473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

why controls keep their state even on a different page?

I have
1. A main form with 2 buttons (btn1 and btn2) and a place holder (ph)
2. A Web User Control (ctl1) containing a textbox (txt)
3. A Web User Control (ctl2) containing a textbox (txt)

When I press btn1 I have the following code:
ph.Controls.Add(LoadControl("ctl1.ascx"))

When I press btn2 I have the following code:
ph.Controls.Add(LoadControl("ctl2.ascx"))

In ctl1 I have the following line on form load:
txt.Enabled = False
When I press btn1 ctl1 is loaded and the txt is disabled. When I press btn2
ctl2 is loaded and the txt is disabled. Why the txt on ctl2 is disabled? and
how can I avoid it? Somehow it remembered the state of the textbox from the
previous loaded page. Why?
Nov 17 '05 #1
8 1721
Viewstate is based on a control's position in the hierarchical control tree
and you are loading different controls into the same position each time.
You either need to setup different placeholders so that each set of controls
is loaded into a different placeholder, or manually deal with consequences.

Thanks, Paul Wilson (MVP)
Nov 17 '05 #2
Viewstate is based on a control's position in the hierarchical control tree
and you are loading different controls into the same position each time.
You either need to setup different placeholders so that each set of controls
is loaded into a different placeholder, or manually deal with consequences.

Thanks, Paul Wilson (MVP)
Nov 17 '05 #3
Hm, what is the purpose of a Place Holder then? If I will load always the
same control in this placeholder I will simply put the control itself on the
page. Why would I put it into a placeholder?
I actually tried to clear the viewstate when I load different control but it
didn't work. I tried to clear the view state of the control of the main form
of the text box itself but nothing worked. Any ideas how to clear the view
state?
Nov 17 '05 #4
Hm, what is the purpose of a Place Holder then? If I will load always the
same control in this placeholder I will simply put the control itself on the
page. Why would I put it into a placeholder?
I actually tried to clear the viewstate when I load different control but it
didn't work. I tried to clear the view state of the control of the main form
of the text box itself but nothing worked. Any ideas how to clear the view
state?
Nov 17 '05 #5
forget the 'position' stuff give the conflicting controls different names
that has solved this problem for us.
"Bisser Milanov" <bm@bm.bm> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Hm, what is the purpose of a Place Holder then? If I will load always the
same control in this placeholder I will simply put the control itself on the page. Why would I put it into a placeholder?
I actually tried to clear the viewstate when I load different control but it didn't work. I tried to clear the view state of the control of the main form of the text box itself but nothing worked. Any ideas how to clear the view
state?

Nov 17 '05 #6
forget the 'position' stuff give the conflicting controls different names
that has solved this problem for us.
"Bisser Milanov" <bm@bm.bm> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Hm, what is the purpose of a Place Holder then? If I will load always the
same control in this placeholder I will simply put the control itself on the page. Why would I put it into a placeholder?
I actually tried to clear the viewstate when I load different control but it didn't work. I tried to clear the view state of the control of the main form of the text box itself but nothing worked. Any ideas how to clear the view
state?

Nov 17 '05 #7
If you have a different placeholder for each possible user control you
may load then the relative positions will be unique. By the way, unique
control ways does not work with viewstate, although it will work if your
problem is just the posted values.

Thanks, Paul Wilson (MVP)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #8
If you have a different placeholder for each possible user control you
may load then the relative positions will be unique. By the way, unique
control ways does not work with viewstate, although it will work if your
problem is just the posted values.

Thanks, Paul Wilson (MVP)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bisser Milanov | last post by:
I have 1. A main form with 2 buttons (btn1 and btn2) and a place holder (ph) 2. A Web User Control (ctl1) containing a textbox (txt) 3. A Web User Control (ctl2) containing a textbox (txt) When...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
6
by: Jim | last post by:
I have a user control that I am dynamically loading into an aspx page. When I fill out the text boxes and submit the form using a command button on the aspx page I lose the value from the user...
22
by: Mr Newbie | last post by:
I was thinking about developing a workflow application yesterday and was musing over the different approaches than one could take in restricting specific actions on a ticket( Form ) at any said...
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
0
JimWu
by: JimWu | last post by:
I have some problems in my code. The stutiation illustrate as the followsing statement. I use two pages, one, named "upload.aspx", is including several general html input tag, whose type are...
3
by: Andy B | last post by:
I have a web form that has controls to be modified on it. The class that will modify the controls is not contained inside the page code. How would I best pass the controls to the external class?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.