473,788 Members | 2,896 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Control Interfering with ViewState

I have a custom control that is essentially implemented as follows:
=============== =============== =============== ===
[ ToolboxData("<{ 0}:TestPanel runat=server></{0}:TestPanel>" ) ]
[ ParseChildren( false ) ]
public class TestPanel : WebControl, INamingContaine r
{
protected override void CreateChildCont rols()
{
this.Controls.A ddAt( 0, new LiteralControl( "<span id=" + this.ID +
">" ) );
this.Controls.A dd( new LiteralControl( "</span>" ) );
}
protected override void Render(HtmlText Writer writer)
{
RenderChildren( writer );
}
}
=============== =============== =============== ===

In a given ASPX I have the following:
=============== =============== =============== ===
<cc1:TestPane l id=TestPanel1 runat="server">
<asp:ListBox id=ListBox1 runat="server" AutoPostBack="T rue">
</asp:ListBox>
</cc1:TestPanel>
=============== =============== =============== ===

The code behind for the ASPX has:
=============== =============== =============== ===
private void Page_Load(objec t sender, System.EventArg s e)
{
if( ! IsPostBack )
{
ListBox1.Items. Add( new ListItem( "1", "1" ) );
ListBox1.Items. Add( new ListItem( "2", "2" ) );
ListBox1.Items. Add( new ListItem( "3", "3" ) );
ListBox1.Items. Add( new ListItem( "4", "4" ) );
ListBox1.Items. Add( new ListItem( "5", "5" ) );
ListBox1.Items. Add( new ListItem( "6", "6" ) );
}
}

*Also assume that ListBox1 has its SelectedIndexCh anged event wired to a
local handler.
=============== =============== =============== ===
When this ASPX initially loads, everything looks fine. However, if a browser
client then selectes an item in ListBox1 causing a post back, the ListBox
control's SelectedIndexCh anged handler doesn't get called and none of the
orginal items are retrieved from ViewState. Inspecting the __VIEWSTATE field
sent to the client after initial page request and then the subsequent
postback showed that value goes from something relatively large to something
arbitrarily small (the digest/hash value of a blank ViewState I assume),
confirming to me that something is causing ViewState not work properly.

To compare, if you change the ASPX page to look like:
=============== =============== =============== ===
<asp:ListBox id=ListBox1 runat="server" AutoPostBack="T rue">
</asp:ListBox>
<cc1:TestPane l id=TestPanel1 runat="server">
</cc1:TestPanel>
=============== =============== =============== ===

.... removing the ListBox from the TestPanel container, things seem to work
fine; SelectedIndexCh anged is called, the ListBox retains its items between
requests, and the __VIEWSTATE field doesn't seem to loose its value.
Why is this happening? What do I need to do to get child controls of my
container working?

TIA//

Nov 19 '05 #1
0 1095

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

Similar topics

0
1032
by: Emrah Gozcu | last post by:
I have a custom control tabstrib and it loads another custom control when clicked a tab. Tabstrib event fires well but the other custom control which is dynamicly loaded after clicking a tab, does not fire its event! This is a common issue i beleive. I use the code in OnPreRender to find get the event but it is ugly! if(Page.IsPostBack && Page.Request.Form != null)
2
3199
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp The problem I am having is that the data in the custom datagridcolumn is not saved to viewstate and after postback, the column does not contain data.
2
1358
by: BluDog | last post by:
Hi I have a created a custom web control called ImageBrowser, extract is below: <Code> #Region "Properties" Public Property Images() As ImageCollection
3
1869
by: Chris Newby | last post by:
I have a very simple custom control that derives from WebControls.Panel and implements INamingContainer. It appear that controls created as children of my custom control are having ViewState problems. For example, suppose I create a ListBox control as a child of my custom control, attach a SelectedIndexChanged event handler to it, and bind its data in the Page_Load event handler only if the current request is not a post back. I load the...
7
3020
by: Shimon Sim | last post by:
I have a custom composite control I have following property
0
1769
by: spacehopper_man | last post by:
hi - I am writing a "tab" control. - but it's losing the viewstate of the content pane when I switch between tabs. can anyone shed any light on why I'm losing ViewState based on my simple example below? - if I put the tabs at the top of the screen viewstate is lost -
0
1407
by: bminder | last post by:
I have a web user control that contains a serializable class. I persist this class in viewstate, but on postback, the viewstate is null. Is this behavior by design? This technique works fine on regular pages -- just not in a control. Is the main page's viewstate interfering with the control's viewstate? Thanks,
3
1266
by: Chu | last post by:
Hello All- I've got a Custom Web Control that with a public class that that sets a private variable inside the class. I plop the custom control onto my page and off I go. From my main page, I call the customPage.loadPage(10) and pass in a value of 10. The loadPage method sets var1 = 10 as expected; however, when the customPage's button is clicked and the page is posted back, var1 is set back to it's initial state of -1.
0
1666
by: Walter | last post by:
Hi, can someone please help me with my custom control viewstate problem....I haven't slept for hours trying to get this fixed. I am making two custom controls which will be included on a single page. For now, I will call them box1 and box2. Each box has a panel and will display a list of link buttons on the panel. When the page loads for the first time, box1 will call the database and create a list of linkbuttons and each link button has...
0
9656
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...
0
9498
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,...
0
10364
Oralloy
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...
0
10172
jinu1996
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...
0
9967
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
6750
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();...
0
5398
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...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.