Solved

asp.net c# Get Dynamic field value

Posted on 2009-07-03
4
756 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
[X]
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
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 250 total points
ID: 24802577
Just put your method call to Page_Init
0

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 asp.net 13 48
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net 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 https://www.mail-signatures.com/articles/signature-templates/?sts=6651 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