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 2346
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*********@no spam.thanx.inva lid> wrote in message
news:sN******** ******@nospamth ankyou.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************ **@nospamthanky ou.spam>, Alan Silver
<al*********@no spam.thanx.inva lid> 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************ **********@u72g 2000cwu.googleg roups.com>, jh*****@yahoo.c om 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.
Upon restarting Access, when an admin is detected (I use a
GetSystemUser() function) I want to restore everything so that Access
behaves like normal, ie. all menus/tbars/etc show up (only where they
are supposed to show up).
|
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 in the user control is pressed the textbox does not
seem to be validated.
How do I even begin to troubleshoot this?
|
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 save viewstate during the previous
request. For example, when adding controls dynamically,
|
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 two days out of 100's of hits.
The error just started yesterday and this app has been running for quite
some time without this error and has not been updated just before or after
the error started.
Reseaching this error I've checked the...
|
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 control but can to get them to
retain view state.
Below is a striped down version of my control. It exposes one property of
type System.Web.UI.Control that the containing page my set with a dynamically
created control My custom control will then...
| |
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 EditStuff.ascx which
reads from an xml file and loads controls to its self based on string value
in xml nodes collection of the xml.
There are several controls that can be loaded and for each one there exists
a public method called 'IntiControl'...
|
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 how those properties are
set.
I want to be able to do two other things:
a) add User control instances to my page, filling in the place of
placeholder controls, and
b) programmatically setting custom properties on those dynamically spawned...
|
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. The number of controls that are displayed can be adjusted by the user
so the controls are added to the page dynamically using the following code in
the Page_Init event handler:
For i as Integer = 1 to NumberOfControls
|
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 = Windows Forms class
B = a singleton hosted within A. B is responsible for dynamically loading
classes X, Y, and Z.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |