How to add text boxes dynamically when one text box is filled? - c#

I have text box to fill the ph.numbers in that, here what i want is, whenever i'm entering the value in that text box i need to add another empty text box dynamically where i can add another value in that in the same way if they are entering any value into this new empty box another empty text box should add at the bottom of this. And after all there is a confirm link button. When clicking on it all these ph.numbers entering on the text boxes should get. How is it possible?

You add textboxes dynamically using jquery and on the button click/submit there values to the server. What you can do is on keyup event of a textbox you can add another below it.

Try this.
I'm basing this condition that your number format is of 11, Ex: 09123456789
So on the Textbox_Textchanged event of your textbox.
if(textbox.text.length >= 11)
{
Textbox text = new Textbox();
text.TextChanged += Textbox_Textchanged; // So it would also trigger the event
// Do positioning here
}
Im thinking you can better optimize this by having a better EventArgs but you get the idea right?

Related

How to create a read only text box

I need to create a text box that the user can't change the value of.
Also I would like the text box to display the value of another combo box and update when that combo box's selected item changes
Please help me.
Click on the Text Box and in the Properties Tab change the value of ReadOnly to “True”
TextBox.ReadOnly = true; should do the trick

Move adjacent text boxes when current text box grows

I am trying to create a windows form with multiple text boxes and these text boxes can grow/shrink. i would like to move the text boxes to its right and below it, based on the text entered in the current text box.
I am growing the current text box using below code
protected void Txtbx_TextChanged(object sender, EventArgs e)
{
TextBox Txtbx = sender as TextBox;
Size size = TextRenderer.MeasureText(Txtbx.Text, Txtbx.Font);
Txtbx.Width = size.Width;
Txtbx.Height = size.Height + 20;
}
FYI I am using a panel to hold the text boxes in each row and grow property set on panel.
Above image is text boxes before the text is entered
Above image is after entering text in textbox.
As you can see current text box is taking over other textboxes ,is there an easy way to move them.
All the text boxes are generated dynamically,so I was planning to adjust the location of other text boxes based on current text box in the same textchanged event handler but i feel its overkill.
Any suggestions?

How to update a textbox in asp.net gridview dynamically

I have two columns in gridview.
One is textbox and the other is also a textbox.
If one textbox text changed , i need to perform some calculation and again need to
fill automatically the second textbox.
(e.g) Ifi enter 10 in 1st textbox, i need to perform some calculation and again the result
of that manipulation needs to shown in the textbox automatically once the text is entered
in the first textbox.
I am not getting a way to achieve this..
please help me.
You need to handle the Leave Event of the first TextBox TextBox1.
Try This:
textBox1.Leave += new System.EventHandler(textBox1_Leave);
private void textBox1_Leave(object sender, EventArgs e)
{
//Do calculations on TextBox1 value to display the result on TextBox2
}

Replace control in repeater with another control

I have a repeater that has a text box and when I enter edit mode on my repeater, I want to replace the text box with a dropdownlist of available options. Is there a way to remove the text box upon item databind and replace it with a dropdownlist for the selected rows index.
Use whatever you are using to indicate edit mode and edit index in the OnItemDataBound event. Then the easiest way is to just hide the text box and show the dropdownlist instead. Whether this works for you or not is dependent on what you're trying to do.

How do I extract values from controls and write it on XML?

I have a form which contains infinite number of options which user and add.
Some options are in textbox, and some are in combobox(selected is the value to be extracted).
The form is in a way that user can add as many combo box and text box he wants and let him write those information onto XML.
How do I code that in c#? If anyone can give me a short example of one each which loops through each added combo box and text box, that would be great.
Thank you in advance.
You can iterate through all controls inside a form like this.
foreach(Control control in this.Controls)
{
//here 'this' is representing the form you want to iterate through
//you can check whether it is a combobox or a text box
if(control.GetType() == typeof(Combobox))
{
//this is a combo box
}
else if(control.GetType() == typeof(Textbox))
{
//this is a text box
}
}
using above method you will find the controls inside a particular form. After that you can write information in a XML file

Categories

Resources