Hello,
I have a products page that takes a product ID in the query string.
Based on the product details (from a database), the page then loads up
one of a number of custom controls, calls a method in the control (that
displays product info) and then loads the control into a placeholder so
it will be displayed.
I want to be able to restore the state of the controls in the custom
control, but can't get it to work. For example, the custom control could
contain a dropdown list for price options for the product (eg, small,
medium and large), and I want to have the user's choice restored after
postback.
Any idea how to do this? I've been searching, but couldn't find an
answer (that I understood or worked!!). TIA
--
Alan Silver
(anything added below this line is nothing to do with me) 5 2322
Alan,
As long as the dropdownlist in the dynamically loaded control has viewstate
set to true then it should retain it's value automatically. All you need to
do is make certain that the control is loaded again and that you don't
re-bind the dropdown (if it's a databound control). If you are databinding
the dropdown just make certain that you only do it on control load:
If Not Page.IsPostBack Then
'---Bind the dropdown
End If
I have some fairly simple examples of using dynamic controls on my website
here: http://www.aboutfortunate.com?page=codelibrary
Use the search box there to search for "dynamic control". The examples may
help you.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Alan Silver" <al*********@nospam.thanx.invalid> wrote in message
news:sN**************@nospamthankyou.spam... Hello,
I have a products page that takes a product ID in the query string. Based on the product details (from a database), the page then loads up one of a number of custom controls, calls a method in the control (that displays product info) and then loads the control into a placeholder so it will be displayed.
I want to be able to restore the state of the controls in the custom control, but can't get it to work. For example, the custom control could contain a dropdown list for price options for the product (eg, small, medium and large), and I want to have the user's choice restored after postback.
Any idea how to do this? I've been searching, but couldn't find an answer (that I understood or worked!!). TIA
-- Alan Silver (anything added below this line is nothing to do with me)
In article <#k**************@TK2MSFTNGP10.phx.gbl>, "S. Justin Gengo
[MCP]" <justin@[no_spam_please].invalid> writes Alan,
Thanks for the reply. I'm still not comletely clear on this, so maybe
you could help me along...
As long as the dropdownlist in the dynamically loaded control has viewstate set to true then it should retain it's value automatically.
OK, we're OK so far. I haven't set EnableViewState to false for any
controls, so we can safely assume that it's true.
All you need to do is make certain that the control is loaded again
I presume this means the actual user control itself, not the
dropdownlist? If so, then yes it's loaded again.
and that you don't re-bind the dropdown (if it's a databound control). If you are databinding the dropdown just make certain that you only do it on control load:
OK, so this is where my main difficulty arises. Suppose I do it so that
the custom control only binds its child controls on loading and not on
postback, would just loading the custom control from the parent page on
postback be enough? I assumed that the custom control would have to redo
all its work.
I haven't tried this yet as it's a bit complex, given the amount of work
the custom control does. I just wanted to get the concept clear. It
sounds like you are saying that all the info about the custom control is
held in view state, but you still need to load it, without letting it do
anything, to see it n the page.
IS this right?
If Not Page.IsPostBack Then '---Bind the dropdown End If
I have some fairly simple examples of using dynamic controls on my website here:
http://www.aboutfortunate.com?page=codelibrary
Use the search box there to search for "dynamic control". The examples may help you.
Thanks, I looked there, but the problem of translating your examples
into what I have done confused me. I think if I can clarify exactly how
custom controls are handled on postback, then I may be a lot nearer my
goal.
Thanks again
--
Alan Silver
(anything added below this line is nothing to do with me)
In article <TR**************@nospamthankyou.spam>, Alan Silver
<al*********@nospam.thanx.invalid> writes I haven't tried this yet as it's a bit complex, given the amount of work the custom control does. I just wanted to get the concept clear. It sounds like you are saying that all the info about the custom control is held in view state, but you still need to load it, without letting it do anything, to see it n the page.
Just to clarify, I did try it and it didn't work. I changed it so that
on first load, the custom control sets the text of some Literal
controls, binds a couple of dropdownlists, sets the visibility of
various placeholders, etc. On postback, none of this is done. The result
was that on postback, the control looked as if nothing had been done to
it, ie none of the work that was done during the initial load had been
saved.
I also tried just restricting the actual databinding code for the
dropdown to first load, but that left me without a dropdown.
So obviously I'm missing something here. I would be very grateful if you
could explain further. Thanks
--
Alan Silver
(anything added below this line is nothing to do with me)
Well, if this works the same way as dynamically loaded non-custom
controls, then you indeed have to reset everything in the load event
for the page.
That was my task -- I had many controls that might possibly be loaded
dynamically, so I ended up communicating from the control to the page
to save stuff in the page's viewstate (since the control's viewstate
was not going to persist). This included an id of the control that was
loaded, so I could load it again at postback and reset all the data.
At that point events in the control would work.
There's many similar experiences in this newsgroup.
Jim
In article <11**********************@u72g2000cwu.googlegroups .com>, jh*****@yahoo.com writes Well, if this works the same way as dynamically loaded non-custom controls, then you indeed have to reset everything in the load event for the page.
That was my task -- I had many controls that might possibly be loaded dynamically, so I ended up communicating from the control to the page to save stuff in the page's viewstate (since the control's viewstate was not going to persist). This included an id of the control that was loaded, so I could load it again at postback and reset all the data. At that point events in the control would work.
There's many similar experiences in this newsgroup.
The word "bleah" springs to mind!!
I'm sure this is a ripe area for future improvements. This must be a
fairly common scenario, but coding it is a nightmare. I got around the
problem by picking up the values I wanted from Request.Form, where (to
my utter surprise), the control values were stored with their original
names.
I'm now trying to do the same for when the info is in a repeater, and
that's being every bit as stubborn as the first problem!! Ho hum.
Thanks for the reply.
--
Alan Silver
(anything added below this line is nothing to do with me) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cefrancke |
last post by:
The only reason I ask is that no one has made this subject clear or
given a definitive answer.
What I would like to do is, after turning off all the menus/tbars/etc
using the startup options.
...
|
by: DesignerX |
last post by:
I have a user control that contains a custom control, both are loaded
dynamically.
The custom control has a simple required field validator and a text box to
validate.
When the submit button...
|
by: Michael |
last post by:
Hi,
Any one know the problem of the following error:
Thanks,
m
Failed to load viewstate. The control tree into which
viewstate is being loaded must match the control tree
that was used to...
|
by: Brad |
last post by:
I have an intranet app that has just started sporadically getting the
following error
"The viewstate is invalid for this page and might be corrupted."
By sproadic I mean 3-4 times during the past...
|
by: Earl Teigrob |
last post by:
I am building a custom control that I want to server as a container for child
controls that can be dynamically added to this control. I can persist the
child controls that are added to my custom...
|
by: Jeff Smith |
last post by:
Can I load custom web user controls dynamically and access the properties
and methods without having to explicitly define custom control types
(example 2 below). I have custom web control named...
|
by: |
last post by:
I have made some user controls with custom properties. I can set those
properties on instances of my user controls, and I have programmed my user
control to do useful visual things in response to...
|
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= |
last post by:
I have a problem with accessing controls that I have loaded dynamically and
added to a web page.
The scenario:
I have a webpage that displays multiple instances of a user control on the
page. ...
|
by: Smithers |
last post by:
I have a Windows Forms application that implements a plug-in architecture
whereby required assemblies are identified and loaded dynamically.
Here are the relevant classes:
A = application =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |