Hi,
I have a webform which has several server controls attached. The entire
form is data bound to custom objects. The collection objects are cached
using the Cache object. In my use case, I have to update my database,
synchronize my cached collection and refresh my UI. After my database
update I call dropdownlist1.d atabind() and my items are exactly the same
when they should be less 1 item. If I understand the "control execution
lifecycle" document correctly, server-side changes that happen in event
handlers should cause the dropdownlist to update because they happen before
the pre-render event. Perhaps I've misunderstood the document though. Any
thoughts or advice would be greatly appreciated.
Thanks,
Bryce
<Sample Code-Behind>
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
namespace BindingTest
{
/// <summary>
/// Summary description for ColectionBindin gTest.
/// </summary>
public class ColectionBindin gTest : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Drop DownList colorList;
protected System.Web.UI.W ebControls.Butt on btnRemove;
ArrayList colors = null;
private void Page_Load(objec t sender, System.EventArg s e)
{
if (null == Cache["items"])
{
colors = new ArrayList();
object[] items = new object[] {
Color.AliceBlue ,
Color.Beige,
Color.Black,
Color.ForestGre en
};
colors.AddRange (items);
Cache["items"] = colors;
}
else
{
colors = (ArrayList)Cach e["items"];
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.colorList. Load += new System.EventHan dler(this.color List_Load);
this.btnRemove. Click += new System.EventHan dler(this.btnRe move_Click);
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
private void colorList_Load( object sender, System.EventArg s e)
{
if (!IsPostBack)
{
colorList.DataS ource = colors;
colorList.DataM ember = "Color";
colorList.DataT extField = "Name";
colorList.DataB ind();
colorList.Items .Insert(0, new ListItem("-- Choose --", String.Empty));
}
}
private void btnRemove_Click (object sender, System.EventArg s e)
{
// Retrieve item from cache
Color theColor = (Color)colors[colorList.Selec tedIndex -1];
if (Color.Empty != theColor)
{
// Perform some database action
// ....
bool dbUpdateSuccess ful = true;
if (dbUpdateSucces sful)
{
colors.Remove(t heColor);
// the following call never updates the dropdown items
// when according to the execution lifecycle it should
// even if viewstate is enabled because the pre-render event
// for this control has not fired yet.
colorList.DataB ind();
}
}
}
}
}
</Sample Code-Behind >
<Sample Webform>
<%@ Page language="c#" Codebehind="Col ectionBindingTe st.aspx.cs"
AutoEventWireup ="false" Inherits="Bindi ngTest.Colectio nBindingTest" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Colectio nBindingTest</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "FlowLayout ">
<form id="Form1" method="post" runat="server">
<asp:DropDownLi st id="colorList" runat="server"> </asp:DropDownLis t>
<asp:Button id="btnRemove" runat="server" Text="Remove"></asp:Button>
</form>
</body>
</HTML>
</Sample Webform> 0 1153 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: patrick_a |
last post by:
Hello,
I am trying to insert multiple instances of a custom user control into a
placeholder on an aspx page, based on the records retrieved from the
database. I use the datareader to loop through the records and I want to
create a new instance of the user control for each record and then change the
properties of the controls within each user control. The problem is that
after I create the new instance of the user control, I get a...
|
by: dasein fiasco |
last post by:
I'm sure this is a design question that is commonly encountered, but I
can't find any resources which explain how to solve it. I would deeply
appreciate any advice.
Basically, when building a composite server control, I'm trying to
avoid having to build the control twice. Here's why this happens:
The routine for building the control can be called from two places:
(1) CreateChildControls, or (2) DataBind. If DataBind is called, it
sets...
|
by: Daves |
last post by:
hi,
sorry for re-posting but it's a simple question and ought to have a very
simple solution; I am trying to use Findcontrol to grab a Button control
within a Formview control:
<form ID="Form1" runat="server">
<asp:FormView ID="FormView1" Runat="server">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Breyta" CommandName="Edit"/>
...
|
by: Unforgiven |
last post by:
I have an ASP.NET page with 14 different text box on it that gets data from
a SQL Server database. Please see the following code.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill(DataSet11)
If Not IsPostBack Then
'This works
'TextBox1.DataBind()
|
by: Mark Olbert |
last post by:
I have a "master" composite control which, in turn, holds an instance of a "detail" composite control (the "master" control will
ultimately contain multiple instances of the "detail" control, but I'm keeping things simple to try and figure out what's going
wrong). The master control supports databinding.
Upon postback, the detail control is not retrieving its state from ViewState after it is created and added to the master control
during...
| |
by: Mark Olbert |
last post by:
This involves a family of related, databound ASPNET2 composite controls.
I've managed to arrange things so that the composite controls restore themselves from ViewState on postback after they're initially
configured during DataBind(). Thanks to Steven Cheng for pointing out that you have to set the constituent control properties after
you add them to the composite control collection for the restore to work!
However, I now have a...
|
by: Owen Blacker |
last post by:
I've spent loads of time Googling to try to work this one out and I'm
sure it's something obvious.
I get an InvalidOperationException reading "Databinding methods such as
Eval(), XPath(), and Bind() can only be used in the context of a
databound control" when I start my page. Unless I'm missing something
obvious, this is *not* the same issue as the "2-way databinding
cascading lists" issue in...
|
by: Arpan |
last post by:
In order to populate any server control with data dynamically, is it
ALWAYS NECESSARY to either BIND the DataSource to that server control
or call the DataBind method of that server control?
For e.g. consider the following code:
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
'create an array of colors
|
by: Jonathan Wood |
last post by:
I have a databound dropdownlist control. Based on some other criteria, I
need to specify the selected item in my pages Load event.
The problem is that, in my load event, the control does not yet have any
data. I've found I can call DataBind() on that control and then it works
okay. However, this has me wondering where the control normally databinds,
and if me doing it manually would actually introduce the overhead of having
the control...
|
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: 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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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: 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...
|
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?
| |