Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asp.net c# Get Dynamic field value

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

772 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