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.
Related
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.
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
First off, I have managed to create a web application where my dynamically created user controls are recreated and repopulated with the correct information upon postback. I am not sure what my problem is, but i hope that you will be able to help me figure it out based on my situation:
On my page i enter the number of controls to be created into a hardcoded textbox (its on the aspx page) and click the okay butten. This in turn, creates the specified number of user controls dynamically using c# in the background.
So far the desired number of dynamic controls are in a table on the page.
Next...
I have 1 textbox and 4 dropboxes on each dynamic user control. When i type a company name into the textbox field and press enter or click away (on text changed event) it autoposts back and the textbox retains the company name that i have typed in.
Based on this string the dropboxes are populated from the database. Now when i select the desired items from the dropboxes and click on the save button (located outside of the dynamic controls, on the page) it does an insert to the database, but it turns out that upon this postback the indexes from the dropboxes have been reset and the wrong values get inserted.
The following pictures show firstly, how it should be and then how it is.
Basically the company name remains in the textbox of the dynamic control, but the information i choose from the dropbox resets to the first index.
It's hard to tell what happend without code, but this is a common mistake:
If you fill/create the dropdownlist controls in the page load event and you post back, the code will refill/recreate the controls. That's why you have to use something like If(!IsPostBack) in your page load event. Otherwise it will execute that code everytime you do a postback and actually just want to execute the code in your event handler for that button.
If you're dynamically creating the controls, make sure to do that in the Page_Init event. Dynamic controls have to be recreated on every postback. Their state is restored after the Page_Init (if it is a postback), so make sure to only set their values in Page_Load if you want to overwrite them.
I am dynamically generating the form based on the drop down selected.
The form consists of fields (data entry for decimal values + few text fields). Have to add all the decimal values at the end and update the Total TextBox with that value. Total Textbox is disabled.
When I click Save button on the form after the user have entered their values, whole form is persisted in viewstate except the disabled textbox. When I enable the textbox, everything works fine. Mind you, I am dynamically generating the form and updating the value of the total textbox using javascript to calculate (adding all decimal fields).
P.S. I am doing everything right for persisting the viewstate.
So what has the enabled/disabled got bearing on the viewstate
Basically, I added two statements to get it working.
txtBox.Attributes.Add("readonly", "readonly");
txtBox.Style.Add("color","gray");
When I used txtBox.Enabled = false, it didn't persist viewstate but did it alternatively using above two statements in my code-behind page
Yes, disabled form element will not send it's value to server side, you can look request header. disabled element not appeared at "get" or "post" collection.
If you want set user can't edit it, you can set it as readonly.
Add javascript on the page:
function enableTextBoxes() {
$("input[type='text'][disabled='disabled']").removeAttr("disabled");
}
And add to server code (in Page_Load, PreRender or some else method)
ClientScript.RegisterOnSubmitStatement(typeof(Page), "enableTextBoxes", "enableTextBoxes();");
If you use UpdatePanels then utilize the ScriptManager.RegisterOnSubmitStatement method
Please create custom text box rather than using actual textbox instance.
inherit textbox in your custom textbox and add this textbox in your dynamic form.
I have a strange problem. While populating formfields, the values are maintained when clicking a'submit' button that causes the page to proceed to the next stage. I try to populate a hidden field from the code behind on the event of a 'find 'button click (before clicking this 'submit' button and this works. But the value is not maintained within the hidden field when clicking the 'submit' button of that page.
Any ideas why this is?
Thanks,
(Edit to clarify) The value of form fields gets posted back to the server when the form is submitted. If you have an input that is set as type hidden and you set the value of it such that it renders in the source (look at the source after hitting your find button) then the new value will post back as well.
Check if this is the case or if you have anything else overwriting the value.