Avoid same messages in ValidationSummary - asp.net

I've a form with several RequiredFieldValidators.
For now, when a required field isnt completed there s an "*" next to the textbox and then the message in the ValidationSummary. But when there's, for instance, 3 required field uncompleted my ValidationSummary looks like this:
required
required
required
How can I have only one -required?

You can't. Best solution for this is to set the input name (Name, Website, etc) for the error message property. Then the user can intuitively determine which field they need to fill in.

Related

Radio Button List validation

I want to validate Status three ways:
Status is a required field: a user must select one status.
If user selects Accept, then:
Qty Rejected should be Disabled
Comments are not compulsory. The user may leave a comment or not.
If user select Reject, then:
The user must put valid range of Qty Rejected, from 1 to 1000 with no non-numeric characters.
Must place a Comment.
How can I achieve this?
Javascript would be your best route for this. An easier route would also be to use jQuery.
Always recheck the information passed to you server side again. I know it seems redundant, but it's for your safety and it provides a better user experience.
You can choose to use javascript/jQuery for all the validations. But you can also use Data Annotations, [Required].
So, using your numbers above:
1) you can use the Data Annotation or JS/jQuery.
2) You can will have to use Data Annotations and/or JS/jQuery. The Data Annotation can handle making sure the input is a number and between 1 and 1000. You will have to use JS/jQuery to check if the Accept/Reject radio button was selected, or disable the Qty Rejected input based on the radio button selection.
3) The comments section can be declared required using JS/jQuery based on the radio button as well.
Info/examples on javascript validation: http://www.w3schools.com/js/js_validation.asp

Remove duplicate entries from validation summary asp.net

I have a validation summary control on my page and my required field validators are in a list view. The listview can have any number of items, therefore I will have multiple validators with the same message. For example my list view could have 5 textboxes asking for a name, each textbox has a required field validator attached to it with the message "Please fill in your name". In my validation summary it shows 5 error messages all saying "Please fill in your name". How can I make it so that the validation summary shows one error with something like "Names are required".
Any help is much appreciated.
Thanks
Look into using a Custom Validator. You can set the error message to "Names are required", and then in the custom validation check the status of each of your name fields. You can also wire up a Client side script with ClientValidationFunction as well.

How to create a form with variable no. of field set

I have to design a page for user information, for some background verification purpose, at my work. I need a set of fields for address, total count of which will be selected by user to update the form with that many fields. So, if user selects 3, form will have 3 set of address fields. Similar concept for work and education details.
Right now, I am passing the count to a handler page, which checks total count, and return it along with querystring, back to the main page. I am able to update the no. of fields, this way, but, all values are lost, once I return to the form. There are a lot of fields to even use session object for every value. Also, it resets the count of other such field set to 0. So, if I select 4 in address field, it renders four set of address fields, but fields for other details are gone.
I need to know, if it is possible to update the fields, using just one page, instead of creating a handler file to handle the redirect, so that I don't lose other data.
Sorry, for sounding a bit confusing. Will update the question, if needed.
Edit:
Similar blocks are there for education and work details. I want the update button to update the block, with that many fields, while retaining the values already entered by the user.
I have finally shifted the update code to one page. And the total count of blocks, is calculated by this way.
if request.form("addresscount") <> "" then
varaddresscount = request.form("addresscount")
else
varaddresscount = 1
end if
varaddresscount is used to loop through the html code which renders address fields. Even with this method, if I click on update button to change the total field count, every value entered by user is reset to default. Is there a way to retain the no. of fields without using session object, as there are way too many fields for which I have to store the value in session.
Why not have just a "add address" button that, whenever clicked, adds a extra set of input boxes using Javascript? That solves a lot of your problems regarding retaining the data on already filled in fields AND it makes it easier for the user.

Need validation check which prompt as soon as user leave the control

We are developing an application where we have a Form to fill by users. Here is the scenario for some fields:
Name : Does not contain numbers like 123 but it can be alpha-numeric like mynangal123 but does not contain special characters
DOB : Does contain specific formats like mm.dd.yyyy or dd/mm/yyy or yyyy/mm/dd etc. doesn't contain alphabets
TAXID : Can be Numeric but not numbers like it can be "123" but not 123 also it can be T-125
Now, as per requirement we have to validate or prompt the user for specific input if he/she did not enter the specific entry. Like if in name User enter 123456 then there should be a messagebox to warn "please enter a valid name"
Restrictions : We have a option of Javascript but its not recommendable in most of scenario so, we need to create a custom validators or something else which will solve our problem.
Please provide some feasible solution for the issue.
Thanks in advance.
Use Custom Validators for this. They provide support for server side & client side validation.

Processing variable number of form fields

I am working on a form which displays information about orders. Each order has a unique id, but they are not necessarily sequential on the form. Also, the number of fields can vary (one field per row on the form). The input into the form will not be mapped straight into the database, but will be added to the current value in the database, and then saved. An example of the form is in the picture below - the callout on the right shows the id for each row.
I know how to generate the form like this, but I can't work out how I can easily process each of these rows reliably. I also know how to give each of the fields a unique identifier, like name="order-23" or name="order[23]", but how can I translate that name so that I can update the related record in the database?
EDIT: One solution I can think of would be to iterate through every form field in the FormCollection, and if the name of the field matches the pattern, then I will extract the number from that field-name and process it.
However, I feel that there must be a much easier way to go about it - this method would likely involve a fair bit of string processing on each field, and there would possibly fall over if I have to add extra fields for each row later on.
Don't you have a list of IDs after postback? I believe you should not depend on what IDs are actually sent from the form, as anybody could change the IDs on the form to whatever they want, so it's a security issue. So you should after postback have a list of IDs you want to update (the same list you used to create the form with). In that case, you know exactly what id string you should use to retrieve the value from FormCollection.
In case you really can't get the list of IDs you are going to update, just use the FormCollection iteration as you suggested in your comment. The string processing is not that expensive in comparation with all other stuff being done at request processing.
If you have the names, then simply read the values by using Request.Form["order-23"] or re-create the controls in page pre-init and you'll have access to the values in your save event directly through the created controls.
I've done this loads in my CMS.
Essentially i sort of cheated.
The idea is something like this ....
render the form to the client, then look at the source code gneerated.
You should see that it generated a form tag with an action attribute.
When you click the submit button the form will be sent to that url so in the case of an order submission you would post the page back to OrderPage.aspx?OrderId=xxxx
then on the server you would build an update statement for your db that contained something like ...
"Update orders where order id =" + request.querystring["OrderId"]
So how do you update the action ...
In the calling page lets say you have a link called "New Order", when that link is clicked you need to do 2 things ...
redirect to this page.
generate an order id for this new order.
ok the first is simple, simply link it to this page.
the second ...
if this page is not a postback if(!IsPostback) { /* get a new id */ } depending on your order id's this may involve generating a new guid or doing something like getting the next number in a list by doing a select max(id) from a db.
once you have this new id you should still be in the page_load event.
this.form.Action = this.form.Action + "?OrderId=" + yourNewOrderId;
... tada ...
Send page back to the client.
view the source.

Resources