Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

Solved c# Get Dynamic field value

Posted on 2009-07-03
Medium Priority
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 750 total points
ID: 24802577
Just put your method call to Page_Init

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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