No additional postbacks work if validation fails on first postback - javascript

I have never noticed that ASP.NET automatically shuts down all subsequent postbacks until the field that validated as false is fixed by the user.
My scenario:
I have a form with 3 fields. One of them is a Textbox (txtCarName) with a required field validator and then I have a dropdown(ddlCarMake) with AutoPostBack=true, that filters and enables another dropdown (ddlCarModel) OnSelectedIndexChange.
Lets say the user clicks the save button without filling out the required textbox (txtCarName). They will be notifed that it is a required field.
Before they go and add a value to the required textbox lets say they decide to edit the ddlCarMake because they change their mind. In this case the filter does not happen since all subsequent postbacks are disabled. The user would be extremely confused.
How do ASP.NET developers avoid something like this from creating a poor user experience?
UPDATE:
After contacting Telerik they told me this is a known issue and is currently fixed in their internal build. The next release it will be fixed.

set the dropdownlist CausesValidation="False"

Related

How to make a button seem enabled for UX reasons, however it is supposed to be disabled

The Title seems a bit confusing so let me explain.
A button does have the property .setEnabled("false"), in which case it will be disabled i.e. you wouldn't be able to click it. However for cosmetic reasons i would like for it to be clickable (as if .setEnabled("true") had been called) but the functionality to be disabled. If the user fulfilled a specific Form, they can submit it, if not they get an Error message.
What I tried: this thing with Button.setEnabled(false)
sap.ui.getCore().byId("Button").setEnabled(false)
Expected Results: For it to be clickable, however if the form is not fulfilled, there should be an Error Message.
Actual Results: Unclickable Button
Instead of disabling the button you should add form-field-validations as described in the Fiori UX guidance. If you in addition need some checks to be performed across several form fields, you can then handle the button press to validate the form fields individual status and the combination of its values to raise errors accordingly as explained in the Fiori UX guidance for forms.
Disabling the button is only intended for cases where it makes no sense to press the button (e.g. you are not in Edit mode) and you have the need to illustrate this to the end-user. In all other cases you keep it enabled and present proper error messages.

Chrome Autofill on ASP.NET Partial Postback (Update Panel)

I understand there are many questions and answers surrounding autocomplete and autofill for web browsers. I haven't seen this specific issue raised.
UPDATE: the autofill specifically happens when a partial postback executes inside an update panel
Recently, (chrome versions 70+?), Chrome has begun aggresively autofilling input fields in our webapp when a partial postback is executed. (We use asp.net web forms)
We use the partial postback to dynamically load a user control and add it to the DOM inside an update panel.
Specifically, inputs like the following simple snippet are being populated with an email:
<input type="search" class="newH4" placeholder="Search">
I've tried adding the autocomplete attribute with different values to no avail.
Here is a screenshot of the autofill:
Additionally I have other fields like entering a dollar amount which gets populated with the email as well. Is there a way to prevent this on the latest versions of chrome?
If you have a password field in your form you can add this attribute -
autocomplete="new-password"
<input type="password" placeholder="Password" autocomplete="new-password">
autocomplete="off" should be working, but in lieu of that working and given that it is not a password or email, you could feed it some random string to see if that helps
For example autocomplete="rjftgh"
Note: simply changing the autocomplete attribute to a random string, or even a special one like 'new-password' does NOT work for this issue.
Ultimately I found a solution. It is more of a hack so I'm not too satisfied with it, but it comes from Mike Nelson's answer to the following question: Disabling Chrome Autofill
His solution involves adding input elements with their display property set to 'none' above the inputs that are being autofilled. The idea is that these hidden fields absorb the autofill instead.
I did also learn a bit more about the problem with ASP.NET and Update Panels as well. When the Update Panel triggers a partial postback, it uses an AJAX library. The library contacts the server to complete the update. Whatever AJAX is doing in the background, it is also triggering chrome's autofill logic to reexecute. In other words, whenever I dynamically add a user control, the first input field in that user control's html structure was being autofilled with the user's stored email.
Again, very strange and bad behavior, but the display 'none' input fields did the trick.
If Chrome changes their autofill logic again (they will), I'll update my answer with hopefully a better solution.

Hidden field validation

I have a hidden value in my form, but when I tried a security scan using HP WebInspect tool, its getting manipulated and shows vulnerability. I tried validating this hidden field but still this tool can manipulate the value. What to do for this?
First of all, check if you're using the last version of HP WebInspect tool (from this point forward HPWT).
Marking a hidden field of one html form as a vulnerability and manipulate it's value cannot be called a good tool.
Check the settings page of HPWT. In the Scan Settings / Method there are options related with forms. Check the autofill web forms options for the forms, and if it don't works set the checkbox for Prompt for web forms values during scan ...
If you don't want the manipulated data affect your code don't try to use this $("#someId").text();.
Hope it help.

Submit a page without select a value for a required radio button

We have a required field on a page where the user has to select Gender which is a radio button with options Male and Female.
What we are finding is that there are cases when the entity has no gender stored in the database. There is javascript on the page
that does not allow user to leave the page without selecting a value. I am trying to figure out if there is a way to find out
continue without selecting a value. Would anyone be able to provide some insight as how it can be done ?
If I disable the javascript the page does not even submit. So there is another way that the user is able to skip a required field. Any ideas ?
Thanks in advance.
It's a good idea to have a back-end form validation check, as well as front-end. That way if users disable JavaScript, or find ways to bypass the front-end form validation check, the back-end will also check the form for errors.
Also, you can just set a default for the radio button, by adding the checked="checked" attribute to any of the radio button genders. This way the user will have a gender radio button already selected by default.
You may also add the <noscript></noscript> tags to your page to check if the user has JavaScript enabled. If the user does not have JavaScript enabled, your page can display a message that the user needs to enable Javascript to use your site.
More info here: http://www.w3schools.com/tags/tag_noscript.asp
It could be done using development tools (like the one we get by pressing F12 on Google Chrome) in modern browsers. As the validation is done through javascript, ie client side, a user can manipulate it from the browser.

Dynamically require textbox when "Other" selected from a drop-down

I'm racking my brain trying to figure this out...
I have an ASP.NET web form with some dynamically generated form fields. Depending on what value is chosen in a dropdown list, visibility is set on the following textbox. I do this with a client-side script.
The intent is a user selects "Other" from a dropdownlist, and the "Other Description" field appears next on the form. I'd like to add the ability to activate a requiredfield validator or some kind of validation on the "Other Description" textbox when the textbox is visible.
Any thoughts on how to accomplish this? In my testing postbacks weren't an option, since the form field needs to be on the page so an empty value is associated with it. (Not my choice - I inherited this code from another developer)
The most common approach would be to always render the validator, but render it as disabled and then enable it when desired.
Take a look at the documentation on ASP.NET validators, paying particular attention to the section labelled "Client-Side Validation" and, more specifically, the ValidatorEnable(val, enable) function.
ValidatorEnable(val, enable) Takes a client-validator and a Boolean
value. Enables or disables a client validator. Being disabled will
stop it from evaluating and it will always appear valid.
Note that the val parameter is the validator element, not a string ID.

Categories