Dynamically Creating Textboxes and DropDown Boxes for input form - c#

I am working on a Nutrition Program that would allow a user to enter in the nutrition information for a item.
this is what my input form looks like every time a user clicks the plus button I need to create three new text boxes and a drop down box which would look like the above example.
This is what I am using right now but it only creates the textboxes for the first click. I need create the textboxes and combo boxes on every time the user clicks the add button.

Nvm,
I managed to do this myself using ViewStates it took alot of code but it works this is adding the controls on button click.
This is re-adding the controls on postback
And this is the results

Related

Asp.net Textbox.Autopostback causes another issue

I have dropdown and texboxes and one button on the form. I'm using 'autopostback=true' for all the form elements. When you fill the form you need to push 'send' button. But because of texbox.autopostback, you need to push 2 time to send form.
If you select dropdown lastly, then there is no problem. But if you're filling textboxes than you need to click 2 time to send form.
Is there any solution for it? I must use textboxes.autopostback='true' but need some solution.
Thanks,
UPDATE:
All controls stays in updatepanel element.
Set a hidden field value to "1" when textbox posts back and its value is valid, else set the hidden field value to "0"
On client-side, in pageLoad event, automatically click the button if the hidden field value is "1". So, to the user button is only clicked once and your auto submitting the form when text post back returns.
Both the above points need to be done in your code-behind.
The result of of this logic will enforce a consistent workflow, where the button can be clicked only once to submit the page.

Need suggestions on best approach to update text entered into multiple textboxes without causing a postback that shifts the page

This is a concept question. I have a web form with 6 gridviews, below each gridview is a textbox. Each row of the gridview contains a question and 5 radio buttons. When a radio button is ticked or text is entered in the textbox it updates the database immediately with one caveat, the textbox is committed when the user presses the tab key, or refocuses curser outside the textbox, or clicks an unrelated button (basically when a postback or textchanged() event occurs).
The problem: There is a delay during postback when the text is committed to the database causing the user to think they can move to the next textbox only to have the curser return to the previous textbox. I added code to prevent the curser jumping but the delay is still an annoyance to users during testing. I added a confirmation message (label) to alert the user when it's ok to move on but when the confirmation message disappears at the next postback, usually when the user ticks the next radio button, the gridview shifts up and the user's curser is pointed to a different line of the grid. This is also annoying users.
Solutions? In my limited experience I have 2 alternatives maybe 3 (below). The reason I did not do either was because I wanted data to update the database as soon as it was typed or ticked. Since the radio buttons cause an immediate update I didn't want the users to inadvertently think the textboxes did too and forget to click a button to commit the text. Since entering text in the textboxes is optional, I don't have a way to validate if the user is done completing the form and remind them to click a button to commit their text input.
Put a button by each textbox to commit the text
Use one button to commit all textbox data when form is complete
Find a way to put a placeholder where the confirmation label is when its hidden so it doesn't shift on postback.
I'm starting to think one Submit button is the way to go and let the user think that is what saves the data? Simple.
At any rate is there a better way to achieve my goals of having input updated in database immediately without annoying delays (postbacks) and grid shifting at inopportune times?
In my case I changed the textbox AutoPostBack property to False and removed all code in the text_changed() event for all textboxes. I am committing the text when a Submit button is clicked. (The radio buttons still commit to db immediately when selected). In the end, I think users are conditioned to click a submit or save button when they finish filling out a form anyway.

Text Boxes and Buttons

I'm a beginner at C# and I'm making this calculator and it has multiple text boxes for different calculations. I've assigned calculator button numbers (0-9) for user input. I can get the number buttons to work for the various textboxes but they are all inputted at the same time. I want to make it so that if a certain textbox is selected, then the user can start using the buttons. Any ideas?
Thanks
You can implement the OnFocus event of the corresponding TextBox. In the method you should set the Enable flag of the Button instance to true where they were originally set to false.
Furthermore you need to keep track of which Textbox was selected last, and redirect output to that one if the user clicks a Button.

How can I load data when I click in another box?

I have an autocomplete on my page where I use it as a search. I want to be able to select an item that appears in the autocomplete and then when the user clicks another box it will do a postback and if there is data for the one selected, it will populate the other fields for that chosen selection.
So what I am asking, is how would I go about doing a postback when the user clicks into another textbox on the screen?
Hi you could use event from textbox (TextChanged) inside this event put your code to verify if this data is correct. Don't forget put property AutoPostBack from textbox in True. This action only can be use if the data in textbox change if for example you put
My Dog
and data not exists if you change focus nothing will happen until you change the data for example
My Cat

c# combobox drop down click deletes everything in textbox

I have a windows program (.NET 4.5) that has a combobox with custom dropdown data. My autocomplete type is set to AppendSuggest, so that the customer can easily type in a name, press tab or enter, and then move on to the next box to fill in.
When the combobox loses focus (goes to another control), the program will parse the text in the textbox. If the name exists in the database, it will attach that person to this instance, otherwise it will create a new person with the name (properly cased) in the database.
Pressing tab allows the autocomplete box to fill in the remaining text and it successfully attaches it to the database. However, if the enter button is pressed or, more importantly, the customer tries to click on a user from the autocomplete drop down list, the textbox simply deletes all text in it and moves on to the next box with nothing in it.
I can't find out how to intercept the data that the user clicks. Ideally, I just want the user to click an item from the dropdown list and have it fill the text in, then parse that text and move on.
I have also checked my code and there is no where in the code that deletes the text from this combobox. It seems to be happening by itself behind the scenes.
Also, I am a somewhat advanced programmer in C#, and although I really haven't worked with autocomplete, I am baffled that I am stumped on something as simple as this.

Categories

Resources