I have a UserControl with a Tab Control containing three tabs. Within the tabs are multiple controls - Datetimepickers, textboxes, comboboxes.
There is also a Save button which when clicked, calls this.ValidateChildren(ValidationConstraints.Enabled) Now, I click save and a geniune validation error occurs. I correct the error and then click save again - valdiation errors occur on comboboxes on a different tab. If I navigate to this tab and click save, everything works fine. How can this be? I haven't changed any values in the comboboxes so how can the fail validation then pass validation?
The comboboxes are bound to a dataset with their selectedValue and Text set. I just don't understand what is happening here.
This behaviour also occurs for some textboxes too. The validation rule is that they have to be a decimal - the default value is zero, which is allowed. The same thing happens, they fail validation the first time - I make no changes, click save again and they pass validation.
EDIT:
The error is not a Framework error - the error is the one I provide during my validation routine. e.g Select a valid drop down option.
I stepped through the process and the sometimes the combobox values are the default values other times the selectedvalue is the default but the text is null. I don't see how this can happen if I'm not changing anything in the combobox.
If you need any further information please let me know
thanks
Barry
The following is a quote from MSDN:
"Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown."
So I'm guessing that if before you press save the first time, you make sure that you've clicked on each tab at least once, it'll work as expected, but if you don't look at all tabs before saving, it fails?
Have you checked that the default value is not null ?
Related
I am currently working with a GridView embedded in a custom user control. The Command field is the default one generated by the GridView itself, and all the buttons work, save for the Update button. The RowUpdating event fires, but the row itself is not in edit mode, so any code I use to attempt to find controls within the row (i.e. the text boxes for the updated values) returns null values.
The only thing I've been able to find so far is this: https://forums.asp.net/t/1475154.aspx
The provided "answer" seems to point at the CommandName value, but I thought the whole point of using the default generated CommandField meant that was handled.
Any help/thoughts on the issue would be appreciated.
Turns out it was just an issue with the page post-back, and when each individual user control fired its DataBind().
In my windows application i have a tab control with many tabs and sub tab controls also, each and every tab has many field like text boxes and list boxes.
i thought to validate every field by clicking button called "NEXT" before changing to nexttab and if any field fails with validation a message box should pop-up with error message and focus should remain in that field. can any one help me with ur suggestions...
validation requirements are required field and only numeric and alphanumeric...
Thanks in advance!!!!
A good way is to create a derived controls with input area and validation logic. Then, it is matter of enumerating hierarchy of controls and see if they are valid based on validation rules applied.
Another way, is to "attach" validation logic to controls. How? A mapping mechanism or use the "Tag" property.
But isn't it better to validate control using "Validate" event, when user tries to exit the control? That will not allow user to supply bunch of trash and hope it can be saved.
I'm using the Extended WPF ToolKit's DecimalUpDown control (v1.7). The control behaves as I expect when using the spinner controls but not when text is edited directly. This is a basic MVVM WPF app with the control bound to a View Model decimal property named CurrentWidth.
In the ViewModel there are various validation rules being enforced for CurrentWidth, at the end of the property it does a RaisePropertyChange("CurrentWidth"); sometimes leaving CurrentWidth unchanged if the value doesn't validate.
All the error checking, value reverting etc works when change is made with the spinner controls. When the user enters text directly in the box, the validation still works but the box is left showing what the user entered. When I send out some debug info, both the Value property and Text properties have the correct unmodified value but the box still shows the user entered value. I tried adding a LostFocus event handler and called InvalidateVisual() on the sender control and even tried an UpdateLayout() as well but after tabbing off the control, the user entered text still shows. Anyone know how to get it to reflect the actual current value?
Download WPFToolkit 1.8.0. This bug is solved there.
I'm using a form (FormView) with databinding (ObjectDataSource) and all my input fields are bound by using '<%# Bind("field") %>'.
Everything works fine, but I have two problems (which I found various hints about like using this.Validate() or .EndEdit() - but none seem to work):
Entries are only saved after leaving the input field so it looses focus
Let's say I have a textbox with an ID of Name and enter "George". When I would tab to the next textbox or when I click somewhere else and click save - everything is saved. But when I keep the focus in the textbox the value is not saved. Why is this happening? What magic can I use to circumvent this (JavaScript to the rescue?).
I set a textbox's field value (element.value) via Javascript (upon selecting something in a combobox).
The same problem as above applies, only when I give the textbox focus and tab out the value is saved. This creates the problem that I only want the user to choose something in the combobox (the textbox is updated accordingly) and move on - I don't want the user to click into the textbox afterwards and tab out again.
Edit:
The second problem I resolved now by setting the focus onto my textbox via Javascript (textbox.focus();) and right after set the focus back to the combobox (combobox.focus();) and that does the trick - this seems fairly hackish to me, doesn't it?
I'm assuming this is fairly common, but my mighty Google fu hasn't help me find a simple solution.
A similar issue can crop up in Winforms development when working with DataGridView controls. I typically attach some logic to the submit button's Click event to cause the DataGridView to validate. I suspect a similar solution would work for you here.
I got this an asp.net 3.5 page that and I have few tabs (telerik tabs control with pageview) and I have panel on the top of the page and inside that has a label control displaying error message if it's any.
At the moment, if I want to display this, at the end of the event clicked button for instance, I have to do a custom URL redirection class to itself passing error message and display the error. BUT the problem with this approach let say you are working on 4th tabs and you click save button inside this then you loose the state of series of control (what's is being choosed, selected, typed etc). The page refreshed and displayed at the first tab again.
I want to display the error and at the same time know the state is for every control on the 4th tabs and automatically goes to 4th tabs. BTW ... this validation is done through server level.
I am appreciated your feedback/suggestion.
Thanks
I see several approaches here:
Make an ajax call with data to validate and show error message basing on its result.
Recover your control state after post back, you will need to write some client logic that will analyze url for some parameter after "#", e.g. http://my-site.com/tabs.aspx#4. Your script will know that you need 4-th tab.
You can try to recover your control state on the server, but I don't know how it is possible with telerick tab control.