ASP.NET validation controls - asp.net

I have a situation where I have a form that has some validation controls for required fields. They fire just fine if the user does not have the required fields.
The thing is I also have a menu above the form which allows the user to select another location which is then reflected on the form.
This is where I run into an issue...
If the user already selected a location and then wishes to change to a different location, the form does not allow for this as required fields have not been entered.
I was wondering if there is a way to tell the validation controls not to fire in these situation.
My other option would be to do a validation on click of the submit button in which case I would not be able to take advantage of the ASP.NET required validation control.
Basically I want the validation to occur for the required fields only if the submit button is clicked.

Look at CausesValidation and ValidationGroup properties. I think they will help you to solve your problem

On the menu item set CausesValidation to false.
You can also use validation groups and set the validationgroup property of the validator and the submit button to the same value.

Related

ASP.NET - RequiredFieldValidator to validate only particular controls

I have a web form. There are many different sections. I can say that each section displays data of a datatable. At each section I have OK and Cancel buttons. When I press OK any changes to the table in the database takes place. I've also put some Requiredfieldvalidators. Let's say I'm inserting a new record in the section one and the fields are correctly typed. When I press OK I get error message raised by the rest of the validators that are on the other sections. Isn't there any way that when I press OK button of a particular section to get validation errors of that same area? So what I probably need is a button that will not serve as the hole page submitter but rather a submitter of a specific section.
Place a ValidationGroup on the RequiredFieldValidator's. Then place the same ValidationGroup on the correct submit button. When its clicked, only validation controls that are a part of the group are validated.
http://msdn.microsoft.com/en-us/library/ms227424.aspx
I think janhartmann is correct ValidationGroup can help you solve the issue.Have a look at this article

textbox - KeyPress event on Asp.net [no javascript]

I'm designing a website and I want my login page to catch "Enter" with all components, but i can not assign any Key or Mouse Events to TextBox ... After pressing to "Enter" a function should be run with 2 parameters (user name and password).
How can i do this?
If you wrap all the controls inside a standard HTML form then hitting enter in one of the text boxes will submit the form. You can then process the username and password entered on the server as with a normal form submission. Is that the behaviour you're looking for?
You don't need to trap any events on the client in this case so no need for JavaScript.
How to submit ASP.NET forms with the enter key
Read up on the defaultbutton property for forms and panels. This should get you what you want. From the site above:
ASP.NET 2.0 introduces a wonderful work around for this. By simply specifying the "defaultbutton" property to the ID of the , whose event you want to fire, your job is done.
The defaultbutton property can be specified at the Form level in the form tag as well as at panel level in the definition tag. The form level setting is overridden when specified at the panel level, for those controls that are inside the panel.
http://www.beansoftware.com/asp.net-tutorials/accept-enter-key.aspx
finally if found the answer. Here is ! The only problem is, I can not hide my button,
so that i put that button to web page as "Login" ... Defaultbutton could be hidden or not?

How to disable listbox's click event

I have a listbox which acts as a list of items. If you click on some item, it's contents are shown in the panel on the right (few textboxes etc.).
I need to have a validation on these controls as all of them are required fields. And I do have it. The problem is that, even when the validators are not valid, user can click the listbox and change active index (that doesn't have impact on the panel on the right, as SelectedIndexChanged isn't fired).
The validators are standard RequiredFieldValidator with their Display property set to "Dynamic". So, what I want is to disallow the user clicking on the listbox and changing the index untill all validators are Valid.
What would be your solution for that? Is that even possible?
Did you try setting ListBox.Enabled = false when you actually do fire off the SelectedIndexChanged, and reenabling when your required fields meet the Page.IsValid requirement to proceed in code execution?

ASP.NET validation

I have a little problem with the validation in one form
the form is composed by two taqs. There is a "Save" button in each tap (is the same control for both) and saves the form info. there are validation controls in one tab but not in the second. When we try to save the info from the second tab, and the info has not been filled in the first tab, the validators fire, and nothing happends, but because this validators are shown in the other tab, the end user might be thinking that the operation has been completed, instead, I would like to show a msgBox telling the user about the errors in the other tab. How do I know that the validators in the other tab have been fired, and display the error message when the button is clicked?
You should use the ValidationGroup of your validator controls and the appropriate submit button. You can also use a ValidationSummary control which displays a summary of the validation messages - this can be set to display a message box if you want by setting the property ShowMessageBox=true.
taqs - tap
dear why are you so confused?
All the validators are posted to the page as JavaScript functions. You can call the validation function on button's click and take the appropriate action.
You can use on buttons
onClientClick="Page_ClientValidate();"

ASP.NET: Only perform validation when Submit is clicked

I have an ASP.NET entry form where several controls have validation set up. The form also includes a display of previous records, each with a LinkButton control that acts as a delete button. Problem is when a LinkButton is clicked, it performs validation on the entry portion of the form, fails, and the delete is not processed. I didn't write this form and I'm not up on the validation controls, and I'm just adding the delete buttons, so how would I work around this?
Set CausesValidation to false for the control in question?
Are you saying that there are buttons on the form that when clicked are causing validation to take place...and that these buttons should not peform the validation?
If so, then you probably need to group all the controls and buttons that are part of the validation. To do this you set the 'ValidationGroup' property for each control involved in the validation (this includes the buttons that fire off the validation).
This should stop buttons that are not part of the validation, firing the validation process.
Check this link out:
http://www.w3schools.com/ASPNET/prop_webcontrol_imagebutton_validationgroup.asp
and
http://www.dotnet-guide.com/validationgroups.html

Resources