Once I successfully validate user data in a TextBox (using TextChanged EventHandler), I'd like to programmatically tab to the next input control. I know I could hard code the name and do
Score2.Focus(Windows.UI.Xaml.FocusState.Keyboard);
but I've got 20 TextBox controls on the page page and I'd like to use the same EventHandler for all of them.
While it may be possible (iterate through the page's control inspecting their tab order and selecting the appopriate next control), I would recommend against it. It will irritate your user if they leave a text box to go back and correct a previous field but your app decides it knows better and gives focus to another field.
Related
I have an excel-like table. The following picture represents a part of it (for clarification, I setted the text of the inputs to be their respective IDs):
There is a ContextMenu that is fired on right click (code here) in each one of the inputs.
Here is how I find all these input controls at once (I need to use this way because there are some more columns that I do not want to call the ContextMenu):
$('[id^="txtF_"],
[id^="txtP_"],
[id^="txtT_"],
[id^="txtE_"],
[id^="txtM_"]').contextMenu({ ....
This works nice, however, if one of the items is disabled, the browser menu shows up instead. What can I do to fire the custom ContextMenu even if the input control is disabled?
I have multiple controls on one form,and when i select some value from combo box(for example 1) next control became enabled, else next control stay disabled.
Problem is that if i just press 1 and tab, after that next control became enabled, but program jump over it just like control are still disabled, and tab control selecting next control.
I need to find way how to tab check is control become enabled and go on this control,and if control are still disabled that go on next enabled control.
Thanx
You created a mousetrap for the user, very hard to escape from. Technically you can handle the keyboard navigation by trapping the Tab key before it can be used to navigate but the user still has an unsolvable problem when he wants to use the mouse to change the focus. He has nothing decent to click on.
You'll need to re-think your UI design. One possible solution is to change the ComboBox's DropDownStyle to DropDownList. Which ought to be pretty appropriate if you use its selected item to enable other controls, there should only be a limited set of valid selections. If that's not what you want then you need to do something drastic. Not necessarily limited to hiding controls instead of disabling them.
This is probably caused by the event of the combo-box you using to control your flow.
The "Changed"/"Value changed" events in most languages fire up after the control has lost focus.
You forgot to add a tag for the UI technology you are using.
If you are using WinForms, then you can try to execute the SelectNextControl method on your control that the user just edited. This will find the 'next' control for you, and activate it.
Lets assume it's winforms (playing with disabled/enabled like this in wpf is.. against mvvm rules).
Firstly, ensure what tab order/index of your controls is ok. To test, if they are all enabled, then pressing Tab should go through them in the right order. This can be seen easily
Next thing is to choose one of many possible solutions, to make 1,Tab to work:
disable Tab key navigation at all;
make controls to pass control (focus) to specific control (making tab order irrelevant);
use SelectNextControl (work best for custom controls, which when will support that tab-flow schema);
prevent focus changing, do all logic, change focus (theoretically).
First off, I have managed to create a web application where my dynamically created user controls are recreated and repopulated with the correct information upon postback. I am not sure what my problem is, but i hope that you will be able to help me figure it out based on my situation:
On my page i enter the number of controls to be created into a hardcoded textbox (its on the aspx page) and click the okay butten. This in turn, creates the specified number of user controls dynamically using c# in the background.
So far the desired number of dynamic controls are in a table on the page.
Next...
I have 1 textbox and 4 dropboxes on each dynamic user control. When i type a company name into the textbox field and press enter or click away (on text changed event) it autoposts back and the textbox retains the company name that i have typed in.
Based on this string the dropboxes are populated from the database. Now when i select the desired items from the dropboxes and click on the save button (located outside of the dynamic controls, on the page) it does an insert to the database, but it turns out that upon this postback the indexes from the dropboxes have been reset and the wrong values get inserted.
The following pictures show firstly, how it should be and then how it is.
Basically the company name remains in the textbox of the dynamic control, but the information i choose from the dropbox resets to the first index.
It's hard to tell what happend without code, but this is a common mistake:
If you fill/create the dropdownlist controls in the page load event and you post back, the code will refill/recreate the controls. That's why you have to use something like If(!IsPostBack) in your page load event. Otherwise it will execute that code everytime you do a postback and actually just want to execute the code in your event handler for that button.
If you're dynamically creating the controls, make sure to do that in the Page_Init event. Dynamic controls have to be recreated on every postback. Their state is restored after the Page_Init (if it is a postback), so make sure to only set their values in Page_Load if you want to overwrite them.
I am developing a dynamic website in ASP.NET. As a trial I tried a code shown below, that adds some controls to Panel1. When user clicks a button for the first time the controls are added to the Panel but when user clicks the same button for second time, the previous controls are replaced with new ones. But I want the controls to be appended one after the other each time the user clicks the button. The code is something like this:
Control c=Page.LoadControl("DData.ascx");
Panel1.Controls.Add(c);
I also tried
Control c=Page.LoadControl("DData.ascx");
Panel1.Controls.AddAt(Panel1.Controls.Count,c);
But this replaces the first output. Please tell me how to append these controls?
As you would expect, this appends a single control:
Control c = Page.LoadControl("DData.ascx");
Panel1.Controls.Add(c);
You can append as many controls as you wish in this fashion.
However, you need to keep track of the controls you are adding in some persisted/stateful fashion (database, Session, ViewState, etc.).
You need to rebuild the control tree every time the page loads.
See my answers to similar questions:
https://stackoverflow.com/a/10050755/453277
https://stackoverflow.com/a/9545079/453277
It may be about the life cycle of asp.net page. Each time when page loads it returns to the initial state. Button Click events are handled after page load and you have only one control at the page. Please look Button to dynamically add controls everytime it's clicked
I have two tabitems. User will enter some data and save it on the first tab. The second tab lists the saved data. What I need is when the user select the second tab before saving data in first tab a confirmation message box with Yes, No and Cancel should be shown. If the user clicks Yes button the data should be saved and go to the second tab. If he hits No, the data need not to be saved and finally if Cancel is hit the tab will retain with all entered data. How can i make this?
To keep things simple you can do the follwing in the Code Behind file.
I'd create a Model class of the data you want to display and edit in the WPF Control. Make the Model implement the INotifyPropertyChanged and IEditableObject interfaces.
INotifyPropertyChanged will allow you to Bind to the Model.
IEditableObject will allow you to provide Edit, Save and Cancel functionality.
The TabControl has a SelectionChanged Event you can handle, that will allow you to detect when the user changes tabs, in this handler you can use System.Windows.MessageBox to ask the user to save etc, System.Windows.MessageBox.Show() returns a MessageBoxResult Object you can use to detirmine what button the user clicked and perform the appropiate action.
This is not a geat way to do things, but it keeps things simple, you may want to look into some WPF design Patterns to help with Code Manageability.
If you need anything explained further, just ask.
Although I disagree with the way you interrupt the user's flow from tab to tab I'm going to humor you and answer the question:
You'll need two things to get this done:
The event that occurs when a tab was clicked
The previous tab that was selected (the one you came from)
The first item:
The tab control has a Click method that you can subscribe to:
Click=”MyTabButton_Click”
The second item:
This part you'll have to do manually. You can set a variable in the click event which contains what tab was last selected. Once this is set you can check a variable (which you previously set) as to what tab was previously selected. You can then do all your validation.
Delphi's TPageControl has an OnChanging event with an "AllowChange" parameter. I guess there is something similar in WPF.