.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

Creating controls at runtime

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :ASP.Net
Hello all, I am creating a calendar tool where you can insert events on certain dates.  Right now I have a textbox where the date of the event is entered and a button that will create another textbox beneath that for a second date.  When I click the add button the second textbox is created just fine, but if I click on it anymore it won't do anything. Here is my code behind for the add button... any ideas?  Dim recurringDate As TextBox = New TextBox() Dim spacer As LiteralControl = New LiteralControl("<br />") recurringDate.ID = "recurringDate" & hdnCount.Text recurringDate.Width = 100 PlaceHolder1.Controls.Add(recurringDate) PlaceHolder1.Controls.Add(spacer) hdnCount.Text = (CInt(hdnCount.Text) + 1).ToString  

View Complete Post

More Related Resource Links

Creating Dialogs and Ribbon Controls for SharePoint 2010

SharePoint 2010 provides new user interface components, such as server ribbons, and the new dialog platform. As a developer, you can create controls for the server ribbon and dialog boxes for the dialog platform.

Creating Custom SharePoint 2010 Field Types and Controls with Visual Studio 2010 and Silverlight 3

Learn how developers can create rich experiences in SharePoint Server 2010 publishing sites using Microsoft Silverlight 3.

Video: Creating Custom SharePoint 2010 Field Types and Controls with Visual Studio 2010 and Silverli

Watch the video that accompanies the MSDN article and learn how developers can create rich experiences in SharePoint Server 2010 publishing sites using Microsoft Silverlight 3.

dynamic creating controls in webpart


Hello everybody,


My webpart (wss 3.0, VS2005) initialy contain a listbox. Depeding on the selection made a certain amount of textboxes are to be created and rendered. Via these dynamically created / rendered textboxes text can be submitted (via a button), for futher processing.


I am not sure how, or where in the webpart code, to dynamically create these textboxes.


Maybe somebody can give me some advise on this topic.


Thanks in advance









Creating ADO.NET Entity at runtime

I'm trying to implement my own Membership provider. I don't want to dig in very details but only high level logic. And first I don't understand is how can I use the class User generated from database in my CustomMembershipProvider project?I thought I shouldn't generate class User in my project which uses my custom provider because it just don't need any users. It's only for login/logout functionality which implements Membership provider, not project that uses it.Then I thought that I should pass Connection String to my Membership provider in order to make UserEntity somehow and use it inside Membership provider. I have two separate project for Membership provider and for any else project using Membership.So my question is... How could I create and use ADO.NET Entity in CustomMembershipProvider project for User table which located in database in other project?

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..."

way to prevent creating, loading and rendering previously rendered controls on postback in a webpart

Hi All, I have a web part and a link control in there when i click it, wp displays rows of data below the previously rendered contents...when i debug it ...web part renders everything from the beginning...so just wondering if there is any way to prevent creating, loading and rendering previously rendered controls on postback?Hanif

Copying the whole layout with controls from one aspx page to another page in runtime

Hello all Here is my issue. I've a page main.aspx. This page has a button 'Settings'. When it is clicked, I load another aspx page settigns.aspx in a popup. Now in the settings.aspx i allow the users to add controls dynamically. For example the user can create 5 textboxes. When he saves it there, I need to get that controls to main.aspx. So i need to move all the controls from one page to another page. I'm not able to think of a solution with user controls. Any ideas on this?

Add WPF controls at runtime

Hi,     I am using VS 2008  - VB.net  and WPF  . How can I add WPF controls on the form at runtime ?       Regards

Creating dynamic web controls outside Init method



I am creating a dynamic <asp:Table> based on a user's selection from a DropDownList. The number of columns and rows in the table depends on the user's choice from the DropDown.

The final two columns in each row needs to contain an Edit and Delete button. I am able to create these buttons programmatically. However, I am unable to get the click event to fire.

After researching this, it appears to be the case that my dynamic Web controls need to be created in the page Init method.

However, I am unable to do this as I do not know how many table rows, columns and buttons to create, until after the user has made a selection from a DropdownList.

I would be be very grateful for some tips on the correct way to create and enable the events for my dynamic buttons, in this scenario.

Here is a brief outline of how the program currently works (this is just a brief outline I quickly sketched, small details may be wrong!):


<asp:DropDownList ID="ddlMyDropDown" runat="server" 
                onselectedindexchanged="ddlMyDropDown_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>

<asp:Table ID="tblMyTable" runat="server" /> 

Error Creating Controls in design view



Some days ago my designer started to show "Error creating control - [controlname] Value cannot be null. Parameter name: parseText" instead of all of my server side controls in all of my web projects - including both framework 2.0 and 4.0 projects. I tried many tips I found on the net, including restarting VS, cleaning the temporary asp.net folders and even I reinstalled the whole VS pack, but I still get the same error.

This occures in both VS 2010 and Microsoft Expression Web 4.

Any help appreciated.



Error when creating a webpart using user controls


I received the following error when trying to create a webpart with user controls. 

Unable to cast object of type 'ASP._controltemplates_UserControl_ascx' to type 'namespace.class'. I deleted all the files from the location
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files, but still the same error occurs.
Here is the code for referencing the user control. 

protected const string defaultUserControlPathField = "~/_controltemplates/myUserControl.ascx";
 protected string userControlPathField = defaultUserControlPathField;
 namespace.class tempControl;
UserControl myControl;
 myControl = (UserControl)this.Page.LoadControl(this.userControlPathField);
                    tempControl = (namespace.class)myControl;

Does anyone have an idea about this error?



Dynamic controls added at runtime, threading, The calling thread cannot access this object because a




My problem is on load I initialise a new thread. This thread create a new control then tries to add the control to a stackapnel and the error I receive is -

The calling thread cannot access this object because a different thread owns it.

Heres is my code e-




t = new

Saving values from controls those decided at runtime


I have a view to create an "Instruction". I need to enter InstructionName, Description, and few Attributes to it. The number of attributes is determined at runtime. When "more attributes..." is clicked we replicate a div which contains AttributeID(a dropdown) and AttributeValue(a textbox). The definition for Create view is

<% @ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<HexsolveMV

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.

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.
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