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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

by:Rahul Goel ITIL
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with Report Viewer in VS2013 6 33
What!!!??? 5 60
Returning multiple values with a stored procedure 9 31
Textbox autocomplete using jquery in 13 48
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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