Radio Button List validation - asp.net

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

Related

Submitting "complex" ASP.net forms using cURL&PHP

I'm trying to create a bot to submit a ASP.net form using cURL and PHP. I'm able to do this with simple forms but I got stuck with one email form that uses a grid. Looking the network traffic when submitting the form I found this as one of the parameters posted to the form:
panForm$cbpEmail$FormLayout$grdFaleConoscoDestinatarios: {"selection":"T","callbackState":"z952aVWEs2XJ9DNtuoB8EI0qtZom3Guwv37Ny34ch6u8rMA6ASD0MLgS8vw+0Bz88+PlMhyGnAlnYDZXOy6C0OCBknNqTSUClocyeoOOYcO6KfoLUvLMZWRTBGRY+WUBG3MKabwqmYopS8A42gKWxUHlS7fr98CEILuzK6NAfyuUbgSD878Xtus2kFakVyx9PCQZTvqmUxRS2yiriUhy2C5SkeEjl7htRbAXdgcHr/PM+TRP3QacVdGk52pEBS0IdkY95M7tI8iW55GuMkvhq3exptJZDfibhBx7dvNuZXKX3ro7tVT2FxZVlgrjqwUBi0mGgbMXHbscXTRRJ71LKXf3GSstqEGffjAoZPyJh8LufZ1I4rvSFTuL/CX4ktLel3JYHAolcf4GGgYGbJcou2g9IWIgRJ5OSfQLJyyah8hu1m+zx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NNqex8sdPe02yFxH4UuDfUjNnWbTyNgH6pMQKuR/a9qTporlwD/4viOc5yyt0/rIs0+tRTL1kew3/uJ5Umcw1QHGc+e7ZTRFR+YnxiQUAKFRhBUvE/JNaAarH1z/qsg8WrDi6yHN/wOoZcGUgBm/2w8iULF5GKvV74xb2jDX5o9xb5c++GjpGDBbVL3Q96UHMAAjRa6u3r4aIbYt2eIQ6p8SjuUKRDNxwDidz7Bq0eO1ahZ0tECcDLAtpjjVbdYLJtL64Z6kHZKSjZwduHtTNzG4XtE9d5NCZITbQ8L2Qtr1jm1ZDYPd2p92yHZgwaNmmtieSsOaxeDNE/l4cVs3kRo5BOXG1V7snk/IOoecMdQ3gJ7UhOMfnD0u4QBRXSrje72ET7jb+RTI=","groupLevelState":{},"keys":["201259","201260","201261","201262","201263","201264","201265","201266","201267","201268","201269","201270","201271","201272","201273","201274","201275","201276"]}
This data represents a grid that is part of the email form where user is able to select who will receive the email.
My question is how can I mimic what ASP.net do to create this data from the grid that is on the page to be able to submit the email form? Does anyone have information about this "callbackstate"?
After submitting a lot of times the same form I realized that I don't need to care about the callbackState. What is important in my case is properly set the selection attribute of this JSON (provided during the creation of the component on the page).
The selection attribute represents the state of the checkboxes in the grid. T means true and F false. selection="T" means only first row selected while selection="FTFT" represents 2nd and 4th rows selected. Remaining rows not represented in the selection attribute are false by default.
Best Regards

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.

Drupal Views and exposed filters - how to reset optional drop-down list filter, or allow "all" selection

I have a view with a filter by country. Country is an optional CCK text field with drop-down list selection from a predefined list.
When I expose the field as an optional view search filter, I can select a country on the filter form just fine, but how can I handle no selection? I want the user to be able to "un-select" any previously selected value so that the query runs for all countries (or, to be more precise, does not constrain the results by country). I cannot add "all" as a value to the CCK field for obvious reasons. Selecting all countries in the drop-down on the search filter is not very user-friendly and causes the page to time out (there are over 200 countries in the list, and I can only imagine the resulting SQL query). Whats the best way to handle this?
I found this View Filters Reset hack which could be helpful. The desire to memorize the last selection adds another complication - when configured in the View properties, and once the (persistent) cookie is set, there is no way to get rid of the selection (short of manually deleting the cookie).
The answer was to check "Force Single" on the filter properties. This made <any> show up as a selection in the country filter drop-down. It kind of makes sense, because <any> in a multiple-selection list could be seen as ambiguous. Still, I can think of valid reasons why a multiple selection filter might be optional. Drupal surprises me every day.

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.

Cannot enable viewstate?

I have a web apllication with wizard control with 4 step index. Each having a dynamically editable grid which need to put only valid data & goto next.
In one step which have 2 columns which are not require to be editable because it has set its value from previous field by calculation, done with javascript.
But problem is that when we decalre these field as a enable false or read only mode then it works but can not able maintain state means its value goes off when we change the step index changed. (If that field are editable then it works ok.)
Also I tried it by use of label field but the same thing happen when the step changes label can not maintan its state (its value clears when step changes).
Please give me idea how to resolve this problem. Also each step has a dynamically created editable grid.
Thanks & Regards,
Girish
Well, if your javascript is doing the calculation from another field that is set by the user, then why couldn't you just redo that calculation on the server side when switching to the next step. I am assuming that the "value from previous field" is getting passed back to the server.
Another solution would be to have your javascript populate a hidden field too (in addition to the one viewable by the user). Then you just read that hidden field.

Resources