Solved

asp.net c# Get Dynamic field value

Posted on 2009-07-03
4
743 Views
Last Modified: 2013-11-08
Hi

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();

                            plc_IN.Controls.Add(lbl);
 

                            TextBox txt = new TextBox();

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

                            txt.ValidationGroup = "preview";

                            plc_IN.Controls.Add(txt);

Open in new window

0
Comment
Question by:ricardomachado
  • 2
4 Comments
 
LVL 9

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.
0
 
LVL 2

Expert Comment

by:nikege
ID: 24776410
You have to place your code to Page_Init evenhandler.
0
 
LVL 1

Author Comment

by:ricardomachado
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.

0
 
LVL 2

Accepted Solution

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

12 Experts available now in Live!

Get 1:1 Help Now