Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have created a custom control that takes input from the application developer at the Degsin time and render the controls depending upon the inputs from the developer. Now Please tell me how to get the values of these controls(text box,button etc).
Posted

Hi Friend,
I am not sure but I guess it can be the answer...

If you have a custom control named MyControl. and it has a text box in it named MyBox01 then it can be accessed like this:
C#
string mydata;
mydata = MyControl.MyBox01.Text;


Hope this can help you.
Thank you.
 
Share this answer
 
Comments
Pratik Golchha 18-Sep-12 2:40am    
Hi Tushar,

Thanks for the reply. See i m using editor for getting developer unit. And adding the input in the list. And when i m rendering the control i m using this list to render the controls(text box,button etc). So the object of these controls are created at runtime.So now please tell me how to access values of the text boxes
Er. Tushar Srivastava 18-Sep-12 2:47am    
Well Now I am understanding it a bit.. What you are trying to do is, you have created a list of objects and use this list to render the control on the form only at runtime.. and now when they are created at runtime, you donot have any option to get values. directly... let me answer you in a while.. I will be doing a test and replying you. Please understand it.. I will surely be back with answer in no more that 10-15 mins... Thanks.. And yes, I have also created such a program long time ago :-) So it's sure that you will get the answer :-)
Pratik Golchha 18-Sep-12 3:45am    
Hi Tushar,
I am developing a web control. And i m overriding RenderContents() method to reneder the control. I am using using a list to load Radio and Drop down depending upon the inputs from the user. User can use this control on its webpage. Now if the user add a button and on the button click how can i get the values pf the control.
Hi Friend,
I am back, and here is the full code that may help you for sure.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test_Dynamic_Form
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        TextBox mybox = new TextBox();
        Button mybutton = new Button();
        List<control> arraylist = new List<control>();
        private void initlist()
        {
            mybox.Text = "Hello";
            mybutton.Text = "Click";
            mybox.Left = 10;
            mybutton.Left = 10;
            mybox.Top = 10;
            mybutton.Top = 40;
            mybutton.Click +=new EventHandler(mybutton_Click);
            arraylist.Add(mybox);
            arraylist.Add(mybutton);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            initlist();
            foreach (Control myobj in arraylist)
            {
                this.Controls.Add(myobj);
            }
        }

        private void mybutton_Click(object sender, EventArgs e)
        {
            mybox.Text = "I am Changed";
        }
    }
}


This program is working fine. It uses a list to generate the controls dynamically on the screen and sets a callback inside this list. So, whenever this callback is called it performs the task inside the function.
As per this code. It draws two controls on the screen, the first being a Textbox and the next is a button, there is a Event callback setup for button click event. This dynamically sets up a callback event and links it to the function mybutton_Click(). Thus the text inside the textbox changes :-)

Hope this code helped you.
Regards
Tushar Srivastava :-)
 
Share this answer
 
v2
Comments
Pratik Golchha 18-Sep-12 3:45am    
Hi Tushar,
I am developing a web control. And i m overriding RenderContents() method to reneder the control. I am using using a list to load Radio and Drop down depending upon the inputs from the user. User can use this control on its webpage. Now if the user add a button and on the button click how can i get the values pf the control.
Er. Tushar Srivastava 18-Sep-12 3:54am    
Implies that you are making some kind of online Web builder application?
Well then I guess I cannot be of any help to you, sorry, because I have no experience in ASP yet I have worked with it too but not with ASP.Net... but it's all right... I will try for some sort of solution and possibly return to you with an answer... i never loose hope :-)
Regards
Tushar Srivastava
Pratik Golchha 18-Sep-12 3:58am    
Thanks Tushar...Could you please tell me your present location.
Er. Tushar Srivastava 18-Sep-12 3:59am    
Yes sure, I am here in Chandigarh :-) Why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900