Solved c# Get Dynamic field value

Posted on 2009-07-03
Last Modified: 2013-11-08

I have created a function placed on a .cs file that gernerates a form containing fields that are read from a database (to send an email for example). The controls (textboxes, etc) are dynamicly created and I also added a button and it's Eventhandler. The creation of the fields has no problem, what I cant get is after clicking the button, retrieving the dynamicly generated fields value (can't seem to reference the fields properly) .

Any help would be apreciated
//Field creation example (working) 

                            Label lbl = new Label();

                            lbl.Text = "<b>" + dr["FORM_FIELD_CAPTION"].ToString() + ":</b> &nbsp;";

                            lbl.ID = "lbl_" + dr["FORM_FIELD_FIELD_ID"].ToString();


                            TextBox txt = new TextBox();

                            txt.ID = "txt_" + dr["FORM_FIELD_FIELD_ID"].ToString();

                            txt.ValidationGroup = "preview";


Open in new window

Question by:ricardomachado
  • 2

Expert Comment

by:Rahul Goel
ID: 24771276
You need to recreate the control again in pageload, irrespective to PostBack. and you must have a event handler attached to your button.

Expert Comment

ID: 24776410
You have to place your code to Page_Init evenhandler.

Author Comment

ID: 24802230
What I am doing is creating the controls from a cs file that is not aspx.cs, so that i can call "from whereever I want".

So I cant use page specific attributes... is this possible, otherwhise I have to do everything inside a page.


Accepted Solution

nikege earned 250 total points
ID: 24802577
Just put your method call to Page_Init

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Login 17 37
Error in script 11 44
How to have a gridview column with multiple items in a column row. 2 7
Not seen Link button 5 0
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now