Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

Dynamically creates TextBox


Posted by :Zill-e-hussain bajwa

This article will show you how to create TextBoxes and DropDownList dynamically on ASP.NET page and then retrieve user input values from dynamically created controls.
I came across the requirement for a project that I was working on, my manager wanted me to accomplish a specific task by sending a message to a particular member of the group. He suggested I should design the screen, where the user can pick a members name from a DropDownList and type a message in a Textbox and submit that information to the system, but at the same time he wanted me to design the system that user would be able to send a multiple request to different members of the group. In this project I have design the screen where user types a message in Textbox and select the appropriate party name from the DropDownList and send that data to database for later process. The question arose how would I retain the ViewState after the PostBack and at the same time recreate the DropDownList control data and retain the TextBoxes control property text value for a multiple request?



Before I begin read my last article Dynamically create Textbox controls from which you will learn how to create TextBoxes control dynamically on ASP.NET page, and also read about how ASP.NET page life cycle works?



In this project I decided to manually assign a control id to the TextBoxes and DropDownList. After creating these controls I just added them to different placeholder controls.



// Add TextBoxes Control to Placeholder

private void CreateTextBoxes()

{

for (int counter = 0; counter <= NumberOfControls; counter++)

{

TextBox tb = new TextBox();

tb.Width = 250;

tb.Height = 60;

tb.TextMode = TextBoxMode.MultiLine;

tb.ID = "TextBoxID" + (counter + 1).ToString();

// add some dummy data to textboxes

tb.Text = "This is textbox " + counter + " da

Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy