Ask a Question related to ASP.NET Building Controls, Design and Development.
-
u3k #1
Custom control viewstate (?) issue!
I've been struggling for a day and yet haven't found a solution to
such a problem:
I have, let's say, an apsx page, which contains a UserControl, which
adds to it's Controls collection a new control, dynamically loaded via
LoadControl, which in order is also a UserControl, visually designed.
When I init this 'dynamic control', i set properties of this 'dynamic'
control's subscontrols (textboxes, labels - all WebControls), on first
load i see this initial, desired, values. But then, after a post back
- those initial value are lost. All viewstate stuff is set properly
thru the whole hierarcy of controls. The weird thing is that even if I
add any text to textboxes containig initial values in browser, e.g.
Initial value was 'Default', and i type up to the end of the string
'!!!!', after postback i get in textbox just '!!!!'.... Seems like
viewstate is restored but in some irrational way - only what is
received in postback! More: even if i will mix the parts of initial
value in browser text box, for example - switch part of the phrase via
cut and paste, theese parts also will be removed from viewstate. And
more: if i'll retype the exact string in browser textbox, the same
that was written in intialization part, but before that _clear_
(DEL-DEL-DEL:) textbox's contents, the string _typed_ is restored...
u3k Guest
-
viewstate and custom control
I have custom control with dropdownlist. I am using this custom control in a repeater. After the post-back the control properties that i stored in... -
Nested control in Web Custom Control and ViewState
I am working on a Web Custom Control that will function as a Tab menu. I am having problems with figuring out what I need to do to link up the... -
Losing viewstate in custom control
I have a custom control I derived from the datagrid control and set a couple of values in viewstate("foo") = "bar" but on postback they are... -
Custom control issue: Where do I put this code?
Billy, this is probably not the answer to your problem, but shouldn't you check IsPostBack before adding those items? -- John Saunders Internet... -
Missing Viewstate in Custom Control
Easy one for gurus:::: Could someone tell me why this custom control bombs during postback? To duplicate: compile this control, put it in your... -
Teemu Keiski #2
Re: Custom control viewstate (?) issue!
Hi,
Do you add the control to Controls collection in Page_Init? If you do, you
need to set initial values on every request, because ViewState tracking
starts after Init.
Same concerns if you first set initial values when loading the control with
LoadControl but you haven't yet added the control to Controls collection.
Control lifecycle, which includes ViewState tracking etc, begins only after
control is added to the Controls collection.
TextBox returning the postback data, is normal, that is how it updates its
state. It updates the value in ViewState with the posted value. I've
explained some of the mechanics of it here:
[url]http://blogs.aspadvice.com/joteke/archive/2004/03/15/767.aspx[/url]
Here's also threads at ASP.NEt Forums related to dynamical controls:
[url]http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=391019[/url]
[url]http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=285389[/url]
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
[url]http://blogs.aspadvice.com/joteke[/url]
"u3k" <u3k@mail.ru> wrote in message
news:d9939e67.0405041020.132442cb@posting.google.c om...> I've been struggling for a day and yet haven't found a solution to
> such a problem:
>
> I have, let's say, an apsx page, which contains a UserControl, which
> adds to it's Controls collection a new control, dynamically loaded via
> LoadControl, which in order is also a UserControl, visually designed.
> When I init this 'dynamic control', i set properties of this 'dynamic'
> control's subscontrols (textboxes, labels - all WebControls), on first
> load i see this initial, desired, values. But then, after a post back
> - those initial value are lost. All viewstate stuff is set properly
> thru the whole hierarcy of controls. The weird thing is that even if I
> add any text to textboxes containig initial values in browser, e.g.
> Initial value was 'Default', and i type up to the end of the string
> '!!!!', after postback i get in textbox just '!!!!'.... Seems like
> viewstate is restored but in some irrational way - only what is
> received in postback! More: even if i will mix the parts of initial
> value in browser text box, for example - switch part of the phrase via
> cut and paste, theese parts also will be removed from viewstate. And
> more: if i'll retype the exact string in browser textbox, the same
> that was written in intialization part, but before that _clear_
> (DEL-DEL-DEL:) textbox's contents, the string _typed_ is restored...
Teemu Keiski Guest
-
Scott Mitchell [MVP] #3
Re: Custom control viewstate (?) issue!
u3k wrote:
> I have, let's say, an apsx page, which contains a UserControl, which
> adds to it's Controls collection a new control, dynamically loaded via
> LoadControl, which in order is also a UserControl, visually designed.
> When I init this 'dynamic control', i set properties of this 'dynamic'
> control's subscontrols (textboxes, labels - all WebControls), on first
> load i see this initial, desired, values. But then, after a post back
> - those initial value are lost.
Are you reloading ALL the dynamically added controls on EACH postback?
No. The default value for TextBoxes (and for DropDownLists) does NOT> All viewstate stuff is set properly
> thru the whole hierarcy of controls. The weird thing is that even if I
> add any text to textboxes containig initial values in browser, e.g.
> Initial value was 'Default', and i type up to the end of the string
> '!!!!', after postback i get in textbox just '!!!!'.... Seems like
> viewstate is restored but in some irrational way
use view state at all. I promise.
I have an article coming up on MSDN about ASP.NET View State. It's not
yet published, but if you drop me your email address, I'd be happy to
send you a draft copy of the article. I think it would help clear up a
lot of misconceptions and strengthen your understanding of view state.
If you are interested, drop me a line at [email]mitchell@4guysfromrolla.com[/email]
Happy Programming!
--
Scott Mitchell
[email]mitchell@4guysfromrolla.com[/email]
[url]http://www.4GuysFromRolla.com[/url]
[url]http://www.ASPFAQs.com[/url]
[url]http://www.ASPMessageboard.com[/url]
* When you think ASP, think 4GuysFromRolla.com!
Scott Mitchell [MVP] Guest
-
u3k #4
Re: Custom control viewstate (?) issue!
"Teemu Keiski" <joteke@aspalliance.com> wrote in message news:<#mzNmrgMEHA.2244@tk2msftngp13.phx.gbl>...
Thanks! It made much clearer to me what happens for dynamic controls,> Hi,
>
> Do you add the control to Controls collection in Page_Init? If you do, you
> need to set initial values on every request, because ViewState tracking
> starts after Init.
>
> Same concerns if you first set initial values when loading the control with
> LoadControl but you haven't yet added the control to Controls collection.
> Control lifecycle, which includes ViewState tracking etc, begins only after
> control is added to the Controls collection.
but... the problem want's there, i've discovered...
What happens: i have several objects placed on Session. After user
logs in, his objects (custom object taht contains user data,
Session["User"]) is put on Session. It lives in in intact just down to
logout. But there are objects that are refreshed each request - e.g.
Session["CurrentObject"], wich represents object whic corresponds a
node selected in website tree. Each requsest Session["CurrentObject"]
is replaced with new refernce to object. So, when in dynamic control I
init values with data from Session["User"]:
TextBox1.Text = ((Controller.ProxyObject)HttpContext.Current.Sessi on["User"]).Login;
.... it all works fine!
but when i use (...HttpContext.Current.Session["CurrenObject"]).ObjectName,
in other words use refreshed object to initalize Text property, i get
behaivoir i've described. I've tried to catch wether control tries to
initialize property when with corrupt data, buti failed - data was
always available.
Weird! How can it be explained?
P.S. Thanks again for links - they had an emmense effect!
u3k Guest
-
u3k #5
Re: Custom control viewstate (?) issue!
Thanks for your reply!
I've sent you an email (from: [email]u3k@mail.ru[/email]) with description of my
problem
more detailed - i've found that it is a bit more cumbersum problem
that i've expected:)
Thanks! I'd love to read it!!!> I have an article coming up on MSDN about ASP.NET View State. It's not
> yet published, but if you drop me your email address, I'd be happy to
> send you a draft copy of the article. I think it would help clear up a
> lot of misconceptions and strengthen your understanding of view state.
> If you are interested, drop me a line at [email]mitchell@4guysfromrolla.com[/email]
>
> Happy Programming!
u3k Guest



Reply With Quote

