.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Removing Controls from a Panel (Not the Usual Question)

Posted By:      Posted Date: October 15, 2010    Points: 0   Category :Windows Application

If I remove controls from a panel using

For Each ctl as control in Panel.Controls

then after removing the control I can ctl = Nothing or ctl.dispose (I can never recall if there is a difference).

But the For Each approach has the problem which has been covered here so often.


If I use another technique, e.g. Controls.Clear or a For i as Integer = 0 to Controls.Count - 1

then how can I dispose the control or set it to Nothing.  (Which maybe doesn't matter but I'm trying to be a very good citizen.)  I assume that I should not dispose the controls or set them to Nothing before removing them.  Right?

Thanks,  Bob

View Complete Post

More Related Resource Links

AJAX update panel and update progress controls

I have writtena Crystal reports web application, that prompts ths user for parameters and then apply them and exports the report to a folder as .rpt and then display the report. I prompt the parameters on one screen and then display the report on another page. I have the AJAX update panel and update progress controls in the parameter page. When the user enters the parameters and click on ok, I export the report and then loads the report to a session report document and transfer the user to the second page where the report is displayed. I use the following code to do transfer to the seconds page. I have excluded the report load and parameter assign code here.rpt.ExportToDisk(ExportFormatType.CrystalReport, "c:\reports\testrep.rpt") Session("rpt") = New ReportDocument Session("rpt").load("c:\reports\testrep.rpt") Response.Redirect("show.aspx") In the second page I have the following: rptViewer.reportsource = Session("rpt") My problem is this works one time and then stops working the second. What I found out was it comes to the statement: Response.Redirect("show.aspx") But it does not even load the show.aspx page. It stays on the parameter page. There are no errors displayed. I could not see any errors when I debug the application also. And out of the blue it works

Arranging Panel controls in a FlowLayoutPanel at runtime?

I have a 10 Panels with visibility FALSE for ALL inside the FlowLayoutPanel. I set the visibility of the Panel at runtime. The problem is that, the order in which the Panel appears different for each & every time when i retrieve the value from db. Because based on the value from db i set the Order of Panel at runtime by making the Panel's visibility to TRUE. At First, when i retrieve the value i am getting the output in proper order same as by value from db. But when the value changes again the Panel is to auto adjust based on the current order from db. But its not appearing for the 2nd time. What i need to do?? Pls Help  Regards TurbulentGeek "Mark as answer if it helped you..."

Custom panel - missing design time support for controls.

I’m trying to implement a custom panel, one that will behave kind of like the standard Canvas panel. The implementation is done and it is working when I add components in the xaml, but what is not working is move and resize of components in the designer. In the designer each component shows the ‘selected frame’ when selected, but it cannot be moved or resized. Can someone point me to what I’m missing, or an article that describes how do add this support?.   The reason I’m not deriving from the existing Canvas is mainly because I want to understand how it works and how to implement it manually.   Thanks  

Dynamically adding User Controls -- newbie question!

I am new to ASP.NET (coming from ColdFusion, thank goodness I'm away from that!).  And I am have THE hardest time understanding how to work with forms in ASP.NET.  Here's what I am doing:Dynamically add User Controls to a PlaceHolder based on some int value (which currently is passed in a HiddenField).Fire an event if the WebControls inside of the User Control change, then handle that event in the Main Page (i.e. save the input to DB)When the user clicks the "Next/Continue" button, the next controls for the next page are loaded.And I guess maybe I just can't seem to get how things work in ASP.NET, because I am really struggling with the general idea of how ASP.NET flows.  Should I be dynamically loading the controls in Page_Init, or Page_Load?  Or should I load the controls when the buttonclick event is fired?Do I have to add the axCtrl.OnDataChange += new EventHandler(HandleAxControlDataChange); line on Page_Load?  Or should I put this in When I first load the UserControl, I need to initialize some WebControls within the UserContorl.  Is there a way to know if I have loaded new user controls into my placeholder?  I can't use Page.IsPostback, because after the first page, every page is a postback from the buttonclick.Any help for this confused newbie would be GREATLY appreciated!!Here's what I have: pu

Modal Popup controls & Update panel

Dear frnds, I have a Modal Popup controls on the page. This will display some data.     It takes around 10 min to fetch the data to display on the popup control.     Code for displaying the popup control is on page behind.   So problem is that it takes 10 min to come up the popup. No indication till them on the page . All the controls are inside the update panel   Regards, Sajid P K  

Question about adding ASP.NET controls to the page later on via programming logic



I'm pretty new to ASP.NET as you'd expect and I'm coming from a PHP scripting background. I am understanding ASP.NET development so far, however, say you have added many controls onto the web page and later on you want to remove a specific block of controls and add new ones, and this is via programming logic (the backend VB file), how would you go about doing this? Or would you have to go for the approach of adding these controls in a container to the web page first - making them invisible - until you need to use them in your programming logic?



Trouble with update panel and dynamic controls and post back


 I have a page that is mostly dynamically built in the page load of my VB.net code behind page.

The issue is that I made a change to the page and added a button that redirects to a secondary page. When the button is clicked there is a very noticeable lag until the button click event fires because the page is being rebuilt every time.

I had not wrapped the code in the load event in the If not ispostback.... because I have dynamic controls that the user interacts with and I need the page to be rebuilt when the user clicks them.

The dynamic controls are clickable table cells. I did some looking and I found that the RegisterPostBackControl. I thought this would be perfect but, it does not although I maybe using it incorrectly.

Here is the code flow.

Page Load

If not ispostback then


end if


private sub setuppage()

'get a reference to the scriptmanager on the master page

Dim scriptManager = DirectCast

update panel woes... question for superstar AJAX gurus



This has got me completely confused... not sure if I've been at it too long and am missing something, or if this is a bug?

I have a webform with an AJAX update panel. In the panel there are 2 controls. One is a textbox, the other a listview.

I'm using the ClientScriptManager to take advantage of the "OnKeyUp" event to cause an autopostback.

When text is entered into the textbox, it runs the textchanged event, which puts data in the listview.

So far so good. All works fine with one exception.

Problem is that with IE8 the textbox loses focus on the SECOND text entry, even though it's specified in my code to focus on textbox after the textchanged event fires. And with Firefox, it doesn't cause the textchanged event to fire at all.

I don't get it??

Here's my code...

    Sub Page_load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load


        TextBox1.Attributes.Add("onKeyUp", Page.ClientScript.GetPostBackEventReference(TextBox1, ""))

    End Sub

    Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox1.TextChanged

        Listbox1.Items.Add(New ListItem("ListboxItem", "ListboxValue"))

        TextBox1.Text = ""


Resizing Panel when adding controls


I have a panel on a form and I am adding controls to it from code behind.

Code behind:
First I am creating TableLayoutPanel
in loop I am adding controls to TableLayoutPanel
and then adding TableLayoutPanel to panel.

problem is I have specified panel height = 100 in designer. how to make it grow when more rows (controls) added to TableLayoutPanel?

At the same time I want to move controls below the Panel to move down..

| Panel		  |  --> I want to make this auto size
| Other Control1  |
| Other Control2  |
| Other Control3  |
| Other Control3  |

I tried setting Autosize=true for Panel and it didn't help!!

Form application with Panel and PictureBox controls: Panel.Clear() does NOT clean. (in C#)


I have been developing a Windows Form application with a Panel and many PictureBox controls. PictureBox controls are created dynamically in the Panel control. The initial display works fine, say with 100 PictureBoxes in the Panel control. Then, the Panel control is cleared by "this.panel.CLear()", for the next display, say new 50 images in the PictureBoxes.

The current situation is that the second display (with new 50 images) seem to be completed AFTER the first 100 images, although the first 100 images are cleaned. This means that the first area where the first 100 images displayed is blank, and the new 50 images are displayed after the blank/white area.

My question is how to display the new images at the beginning of the Panel control.


Update Panel - Speed: Question on how to increase speed



Does the use of update panels increase the speed of a website?

A code sample:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
<asp:Panel ID="Panel1" runat="server" HorizontalAlign="Left" Wrap="False" ScrollBars="Vertical" style="position: relative">
<asp:Label ID="LabelClock" runat="server" Text="Label"></asp:Label>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>



<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">

<asp:Panel ID="Panel2" runat="server">
<asp:Label ID="LabelNumber" runat="server" Text="Label"></asp:Label>



LabelClock.Text is set at every postback in the page load event, to the current time. But the UpdatePanel1 is only updated when the con

Measure question - my desired size changes but parent controls don't catch an ondesired size change


I have an items presenter that contains expanders.  (In order to debug the events, I have a custom items presenter class with an OnChildDesiredSizeChanged event that does nothing more than base.OnChildDesiredEvent.  That way I can debug what I am really working on.

I have a custom expander class that I want to have change its desired size when it is collapsed.  The frustrating thing about expander is that they will update a desired size when you expand, but not when you collapse it.  So I have a custom expander class with my own on collapse event.  The idea is to remeasure the expander.  I had thought that doing so would cause it to notify parents that its desired size changed like what already happens when we expand.

So here is the collapse handler in my custom expander.

protected override void OnCollapsed()
			UIElement hdr = Header as UIElement;
			if (hdr != null)

Debugging I can see the desired size get smaller before and after I call measure.  So my desired size propert

Problems with Repeater Control, Update Panel and the Toolkit controls


Hi Guys,


Having a bit of an issue with the Toolkit controls.

I have a Repeater Control nested inside the Update panel, the repeater item template contains a multiview control allowing users to flick through seperate bits of information. This was working fine the async update was perfect, no issues.

I have then decided to include the rating control to one of the views. problem is now everytime i want to change the view it causes the whole page to postback.  

Attached is the code.

Any help is much appreciated

Scroll/Zoom Windows.Forms.Panel controls


Is there some "thumbnail" or other "easy" way to provide the ability to have a populated panel of UserControl derived objects and scrollbar "move" them and "middle mouse zoom" them on the Client area of the panel?

I am using net FrameWork 4.0  The documentation leaves a tantilizing trail and I sure it can be done, but I do not want to miss something so simple like using the Thumbnail/bitmap/Background properties or methods of the Panel control? 

Thanks Everyone



ASP.NET validation controls are removing client event handlers.


 Below is a tiny section of code to highlight a problem that I am currently having. The textbox has an onblur event (the workings of the onblur event are irrelevant), and an associated RequiredFieldValidator. This code functions exactly as it should. However, if in the body onload event I simply raise an alert of the innerHTML of tr1 or td1, the onblur event does not appear (but it does work, and can be seen when I view source in IE7). If I remove the RequiredFieldValidator, the onblur event handler is shown in the alert, or if I retain the validator but change onblur to onfocus, then the event handler also appears in the alert. I need this to work as when the user increases the Quantity, duplicates of the table row are added (I have tried both cloneNode, and setting the innerHTML of each new table cell to that of the original, but as my alert proves, the onblur event handler is not included in what is copied). The same problem also occurs with onchange for select tags with validators. I am using Visual Studio 2008 (.Net 2), IE7 and IIS 7.

<tr id="tr1" /> 
  <td id="td1" />Quantity <input id="txtQuantity" onblur="fnBlur(this)" type="text" maxlength="2" value="1" runat="server" />   
 <asp:RequiredFieldValidator id="reqQuantity"

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Custom Controls in C# .NET

Embedding user controls in a Windows form is just like adding a simple button or text box that are already provided with .NET. These basic controls were written essentially like you code your own controls. Typically the controls you design are to be used in multiple forms or to modularize your code. These reasons help reduce the amount of code you have to type as well as make it easier for you to change your implementation. There should almost never be any reason to duplicate code because it leaves a lot of room for bugs. So, implementing functionality specific to your control in the control's source code is a good idea. This reduces code duplication as well as modularize your code, which is a good programming guideline.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend