.NETGURU
Maintaining state when using user control dynamic property
Messages   Related Types
This message was discovered on ASPFriends.com 'aspng-pddwa' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Curtis Swartzentruber
Little background for clarity. We have a retail
site selling music product. We will related
a particular title in various ways to content

For instance:

this title relates to this feature
this title is a recommended pick

These relationships are in simple tables such as
TitleID, FeatureID
TitleID, GenreID

There are others as well.

So I often in my data entry backend have the need
to lookup a title either by key (TitleID) or
description (Title) and then put it in one of these
tables. Seemed like a natural place for a user
control.

I exposed a public property where I can pass the
pertinent insert logic from the calling page, since
all the other logic is the same regardless. This
property maps to a private string in the user control.

I can pass in the insert string, but it loses it again
after the first postback. So I put an invisible label
in the user control and set the text property to this
string in my property SET. This is working okay.

Question, is there anything wrong with this approach?
Did I miss something obvious? I haven't been playing
around with user controls for very long. Also, what
is the reason the user control loses the value after
postback. I assume I am expecting state maintenance
when there is none there, is that right?

Curtis

Reply to this message...
 
    
Doug Seven (VIP)

There is nothing wrong with this approach. Another option is to put the
value in ViewState (if ViewState is enabled).

ViewState.Add ("ItemName", "ItemValue" );

Then you can grab it whenever you need it:

(String) ViewState["ItemName"];

The user control is losing its state for one of a couple possible reasons:

<%@ Page EnableViewState="False" %>
This will disable ViewState, and the user control state will not be retained
across requests.
or
The user control is ddynamically loaded on each request, whihc means it is a
new object on each request, losing all state.
______________________________________________
doug seven | sr. developer | dotnetjunkies.com

Learn ASP.NET - Read the books...
Programming Data-Driven Web Applications with ASP.NET
http://www.amazon.com/exec/obidos/ASIN/0672321068/dotnetjunkies-20/107-10642
54-2553318

ASP.NET: Tips, Tutorials and Code
http://www.amazon.com/exec/obidos/ASIN/0672321432/dotnetjunkies-20/107-10642
54-2553318

[Original message clipped]

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification