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

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

Resizing Panel when adding controls

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

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!!

View Complete Post

More Related Resource Links

Cutting Edge: Adding a Context Menu to ASP.NET Controls


Although the context menu is a common element of most desktop applications, it is still fairly uncommon in Web application names because it doesn't map well to a server-based technology like ASP. NET.

Dino Esposito

MSDN Magazine February 2005

Advanced Basics: Adding New Features with User Controls


In past versions of Visual Basic, there were rudimentary graphics controls. In Visual Basic .NET you have the GDI+ library, which enables you to draw lines, circles, and most anything else. But how can you use the functionality of GDI+ to create lines and other graphics that respond to user mouse clicks and events? Find out.

Ken Spencer

MSDN Magazine June 2003

Dynamic Checkboxlist exception when adding to Panel when using Master Page


In essence, I am creating Dynamic Checkboxlist controls and adding them to a Panel.  It works well when I do not have a Master Page configure to this webpage. Once I have a masterpage congifured.. I get a "Object Reference not set to instance of object" error on the Panel_Control.Controls.Add(Checkboxlistnew) line:

protected void Page_PreInit(object sender, EventArgs e)
        XML OXML = new XML();
        alistChkBoxLabels = OXML.XMLTransform("C:\\Documents and Settings\..\\Config_new.xml", "config_options/check_box/applications/app/@name");
        int count = 1;
        alistCheckisFacility = new ArrayList();
        alIDTracker = new ArrayList();
        while (count <= alistChkBoxLabels.Count)

            Checkboxlistnew = new CheckBoxList();
            Checkboxlistnew.ID = count.ToString();
            Checkboxlistnew.Items.Add(new ListItem(alistChkBoxLabels[count - 1].ToString(), alistChkBoxLabels[count - 1].ToString()));

            String sAppName = alistChkBoxLabels[count - 1].ToString().Trim();

            alistCheckisFacility = OXML.XMLTransform("C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2005\\WebSites\\User_Trial\\Config_new

Adding carriage returns between 2 dynamically created controls in an HtmlTableCell


The title pretty much explains it. Here is what i'm trying to do...

 Private Sub LoadGrid_CommentsField(ByVal Row As HtmlTableRow, ByVal BookingNumber As String, ByVal CommentsText As String)
  Dim Txt As TextBox
  Dim Cmd As ClickOnceButton.ClickOnceButton

  Txt = New TextBox
  Txt.ID = "txtComment_" & BookingNumber
  Txt.CssClass = "TFAppControls"
  Txt.TextMode = TextBoxMode.MultiLine
  Txt.MaxLength = 500
  Txt.Width = New Unit(95, UnitType.Percentage)
  Txt.Text = CommentsText

  Row.Cells(cComments).InnerHtml &= "<br/>"

  Cmd = New ClickOnceButton.ClickOnceButton
  Cmd.DisableAfterClick = True
  Cmd.Text = "Save Comments"
  Cmd.ID = "cmdSaveComments_" & BookingNumber
  Cmd.CssClass = "TFAppButtons"
  Cmd.EnableViewState = False
 End Sub

On the line where i try and update the InnerHtml, i get the following error; "Cannot get inner content of  because the contents are not literal."

Adding client event handlers to an ASP.NET controls programmatically



I want to add client event handlers to ASP.NET controls (For example: GridView/Button ) programmatically to ASP.NET.

I am aware of "onclick" event handler, so my code would be

GridView1.Attributes.Add("onclick", "JSGridViewFunction()");

Button1.Attributes.Add("onclick", "JSButtonFunction()");

I want to know what are all the event handlers that are available for (or that can be added to)  ASP.NET controls.

For example, I want to add "onsort" event handler to ASP.NET GridView control.

But the following code fails

GridView1.Attributes.Add("onsort", "JSGridViewFunction()");

Please help.


Adding More File Upload Controls ???

Hi.........I have added a file upload control and tried to upload a image with image name...it was succesfull..Now when i click Add More Photos....i want fileupload controls to be added...(without using JavaScript)like it happened HERE Can anyone help me with this...............

this.controls.add - not always adding to parent form

My current code (snippet below) iterates through user info and adds the same custom control to a form based on how many "Meals" (1-6) the user has selected.  It appears that all even # controls (the second, fourth and sixth) are added to the previously added control, rather than the parent form, when I later try to dispose the controls by iterating through this.controls, only 1, 3 and 5 appear, the others appear as children to 1, 3 & 5. I've reduced controls size, etc. to make sure they're not overlapping (if that can force inheritence?) but no luck.  Anyone have suggestions on what to look at or other guidance? public void drawMealPanel(Meal m, int x, int y) { Controls.MealDisplay md = new Controls.MealDisplay(m); md.Name = m.name; md.Tag = m.id.ToString(); md.Left = x; md.Top = y; md.DragDrop += new System.Windows.Forms.DragEventHandler(this.MealView_DragDrop); md.DragEnter += new System.Windows.Forms.DragEventHandler(this.MealView_DragEnter); this.Controls.Add(md); }

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  

Resizing tab panel

In a tab container after clicking on the Search button a grid will be visible. Now if I change the tab the grid will not be visible. So for that  I made document.getElementById( '<%= dtgSearchresults.ClientID %>').style .visibility ='hidden'; Now what happen I cant resize the panel, the grid is not visible but the size of the page is not refreshed.  Means suppose on the pageload gridview is not visible so at that time size= 100px, when the grid is visible it become 130px and when i move to another tab and come back again on that tab the size is remain 130px though the grid is not visible. Please provide some example and need javascript function only because I made tabpanel property autopostback= false. 

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?



Adding Controls dynamically in the infopath form - A standard Expense Entry scenario



I am having a requirement where I need to create an Expense Report Entry form using Infopath 2010. 

1) The form would have pre-defined columns/Controls like Exp.Type(drop-down) , Details , Location, Amount , Curruncy, Date etc..

2) User can enter/update as many line items as possible by clicking Add/Update/Delete for the each line items. So basically its like adding the same row dynamically.

3) When User Submits, I need to capture this data and post it to SAP where I am using SAP web Services.

Can you please suggest if this is possible in InfoPath form ?

If Yes, how can I achieve this dynamic line items functionality in InfoPath

And how can I read the data using the code so that I can Post it to the WebService? 

Adding controls dynamically


Hi All,
I am creating a questionnaire in a gridview. The questions, answer options and answer control are under CMS. So I am building the questionnaire 'on the fly' adding controls to the page dynamically.

In Page_Load during !Page.IsPostback I bind the question text to the gridview then have another method that iterates through the gridview rows, and adds the controls to a cell eg.gvr.Cells[1].Controls.Add(rbl); The page renders correctly - I see all questions, answers and answer control eg, DropDownList, RadioButtonList, TextBox etc.

The problem is when I try to save the selected options, FindControl cannot find the controls. Even though when I view source I can see all ctrls and ids. I've seen a lot of posts about this issue and CreateChildControl, EnsureChildControl seem to be the route to take. But I don't unserstand how to use them. Can anyone point me to a good example?

And if anyone can explain why it is not working. The page 'looks' to be rendering correctly. Why then are the controls not being found on the postback? Are the controls not being added to the ViewState?


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

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