473,769 Members | 4,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Related Dynamic Controls / Viewstate Problem

pbb
I'm creating a set of dynamic controls on a webpage by calling my
BuildControls sub in the Page_Init sub. I recreate the controls by calling
the BuildControls sub in the LoadViewState override procedure. The set of
controls will not always be the same (based on the selection the user makes
in a static ddl). The controls are persisted perfectly.

The problem I'm experiencing is that when one of the dynamic ddl's (let's
say ddl1) is changed I want to save the value selected so that I can use the
value when the BuildControls sub runs to populate another ddl control (let's
say ddl2) in the LoadViewState procedure. I'm attaching a SelectIndexChan ged
event to ddl1 and setting it's AutoPostBack property to "True". The problem
is that in the LoadViewState proc. ddl1 doesn't seem to exist. I've been
reading a lot about the page execution cycle, but I'm stumped as to where to
save the selected value of ddl1 so that I can use it when I rebuild my
controls (and repopulate ddl2).

I even tried running the BuildControls sub in my SelectIndexChan ged event
since it runs after the LoadViewState sub and the controls exist at this
point. The problem then is I get 2 sets of the same controls. One set is
populated correctly and the 2nd has the original defaults.
Nov 19 '05 #1
1 1918
pbb
Ok, I solved my own problem. In the SelectedIndexCh anged event of my dynamic
ddl (ddl1) I can get th id and value of the sender object and store it in
viewstate. In my BuildControls sub (also called from the
SelectedIndexCh anged event) I check to see if this is a postback and if so
then enumerate the controls on the page looking for a match for the control
id for the one that it is trying to create. In the sub that populates ddls I
check in viewstate to see if "ddl1" exist and if so get it's value from
viewstate and use it in the select statement to populate ddl2.

"pbb" wrote:
I'm creating a set of dynamic controls on a webpage by calling my
BuildControls sub in the Page_Init sub. I recreate the controls by calling
the BuildControls sub in the LoadViewState override procedure. The set of
controls will not always be the same (based on the selection the user makes
in a static ddl). The controls are persisted perfectly.

The problem I'm experiencing is that when one of the dynamic ddl's (let's
say ddl1) is changed I want to save the value selected so that I can use the
value when the BuildControls sub runs to populate another ddl control (let's
say ddl2) in the LoadViewState procedure. I'm attaching a SelectIndexChan ged
event to ddl1 and setting it's AutoPostBack property to "True". The problem
is that in the LoadViewState proc. ddl1 doesn't seem to exist. I've been
reading a lot about the page execution cycle, but I'm stumped as to where to
save the selected value of ddl1 so that I can use it when I rebuild my
controls (and repopulate ddl2).

I even tried running the BuildControls sub in my SelectIndexChan ged event
since it runs after the LoadViewState sub and the controls exist at this
point. The problem then is I get 2 sets of the same controls. One set is
populated correctly and the 2nd has the original defaults.

Nov 19 '05 #2

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

Similar topics

3
3984
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
7
1936
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load different user controls. This loading of user controls is done within the code-behind of the main page. The problem is that before loading a user control in place of another, I need to do a Controls.Add then a Controls.Remove so the viewstate is...
1
4836
by: russ | last post by:
Hi all, Here's a problem I'm having with a dynamic table. Following the guidelines here (http://www.codeproject.com/aspnet/dynamiccontrols.asp), which make perfect sense. The problem is that the table contains a SELECT box populated on the initial load. Every time I postback I'm inserting a column into the table, the dropdown always remains in the last column. First time I postback the dropdown is populated okay. The second time...
4
5043
by: Larry Grady | last post by:
Anyone up for a challenge? I've been struggling with this for a few days and was hoping someone could help me. Pouring through all the messageboards I just can't find the solution. We have a GridView that needs to be dynamically designed, depending on what collection of fields our uses want to edit for their product data. We have 400+ fields of information per product so they're selecting a subset of those fields to edit.
8
2096
by: novus | last post by:
Hi, In ASP.net 2.0 I make a control which add the same controls dynamically. In the oninit event I add the controls to the controls collection. After that the loadviewstate event fills in the information on postbacks. The control can add and delete controls that is why on the postback I don't know how many controls there are. At the moment I am able to get the controls rendering but I have problems to save the count of the dynamic...
3
2587
by: HP | last post by:
Hi there The problem of dynamically created controls vs viewstate is widely known one. To access values of controls they have to be recreated on Page_Load. Unfortunately it causes many problems in the following (rather common, I guess) scenario: The controls are created dynamically. Their number and contents
0
2230
by: Scott Roberts | last post by:
I always thought that the viewstate "keys" included the control ID. As long as the control IDs were unique, there shouldn't be any conflicts. Well, it appears that that may not be the case with dynamic controls. Our application was having a problem very similar to the one described here: http://weblogs.asp.net/alessandro/archive/2008/01/04/failed-to-load-viewstate-typical-problem-with-an-obvious-solution.aspx Unfortunately, the "fix"...
1
4659
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3501
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
0
9589
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, 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...
1
9995
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
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...
0
8872
agi2029
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...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
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...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
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
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.