Windows Form Tabs switching - c#

I have three tabs in a Windows Forms tab control. Currently in Tab1 I have a button that saves the information in a textbox and automatically changes the tabcontrol.SelectedIndex to Tab2. Tab2 then uses the information saved from tab1's textbox.
I want a messagebox to popup whenever the user changes the textbox in tab1, but then manually clicks tab2 or tab3 without hitting the button to save the information.
So in summary, I have it so clicking a button on tab1 automatically sends it to tab2. I want a messagebox to pop up if the button on tab1 is not pressed when the information was changed and the user manually changed the tab.

I think a wizard-like design for your application is more appropriate. Tabs are not supposed to work like that from a user's perspective.
But a workaround for your current situation is:
declare a variable, for example dirty
set this variable whenever any control in tab1 has been edited
clear the variable if the button in tab1 is clicked
check this if tab2 or tab3 is selected

You can use the Deselecting event on the TabControl to be informed when the selected tab is changing. If the tab that is being deselected is the tab with the button on it and the information is not saved, you can display the message box.
Also, depending on what your program does, it may make more sense to go ahead and save the information when the tab changes without even bothering the user.

Related

Need to tap twice on touchscreen to click button in WPF

I have a WPF application that at one point brings up another window where the user can enter text in a field that is selected on open then click OK to save the text. This is working correctly on my desktop using a mouse, but when I run the application on a tablet (Surface Pro) the OK button needs to be tapped twice to save the text. The first tap highlights the button, then the second tap clicks it. Is there any way to allow the user to click the button with just one tap on the screen?
This only happens when the application switches to the new window. The main window only requires one tap to click buttons (Though I have noticed that they require two when switching back to the main window). It seems like this issue has to do with focus or something because if I tap somewhere on the new window before clicking OK, I can tap OK once and it will trigger the click event.
You probably need something like this in your code:
textBox1.Focus();
The other place to consider is the Tab order of the items on the form. Once the focus leaves the textbox, it moves to the next highest tab order object. It should be the OK button.
You can adjust the Tab order by looking at the properties of the objects on the form.
This is a bug in WPF combined with a touch display.
Because the textbox is focused, and you press the button, the textbox gets unfocused and the button gets focus. When the button has focus, you just have to press it in order to save your text.
There really isn't a thing you can do about it, since the touchscreen focuses first on the button before you can fire the event (I think it probaly is a kind of a safety feature).

C# asp.net Maintain tab index after asynchronous postback ontextchanged

Ok, so I've researched this to the end of the earth and can't seem to find a solution that works.
I have a C# application, which is basically a web form made up of radio button lists and text boxes in an update panel. The form has multiple 'sections', each of which the user submits when completed. Each control performs a postback. This is because if the user modifies a section after completing it, the 'section saved' label needs to disappear.
This all works well, except the postbacks lose the tab order of the controls. I have found code examples that save the last control that had focus, which works well for the radio button lists, but because the text boxes post back when a user tabs to the next control (not modifies the text), it doesn't select the next control. The user has to hit tab again and it jumps to the third text box, not the second because technically, the second text box is what had focus after the initial postback. I hope this makes sense.
Any ideas? I can post code if required.
I should probably also add that this page is within a frame of our community portal.

Stateful Winform and Cancel Buttons

With the prevelence of the "OK" and "Cancel" buttons at the bottom of forms/dialogs, it is odd to me that I can't seem to find a "standard" way to save control state.
For instance, I have a checked list box of filters. When the user clicks the OK button, it applies the filters to a data set and the form closes. If the user clicks the cancel button, the form undoes all the checked-item changes and the form closes.
In a perfect world, when the user clicks the "OK" button, the saved control state is overwritten with the current control state and a new-state flag is set. When the form is closing, if the new-state flag is set the form resets the flag, and if it is not set the form replaces the displayed control with the saved control state. That way if the cancel button is hit, all the checked-changes the user made are reset.
What is the best-practice way of handling a cancel button undoing changes to a control, or even an entire form? Is there a best practice solution? I could see this being necessary for text boxes, radial buttons, check boxes, and practically every control, so please try and keep it generic and not specific to checked list boxes.
I would suggest it's as simple as:
Keep the data reflected in the UI separate from the UI itself
When the form is loaded, set its contents based on the data
When the user clicks OK, save the changes to the data model (however that is achieved, which will depend on exactly how you're populating the model)
When the user clicks Cancel, don't save any changes
There's no need to "undo" the changes on Cancel - you just throw away the form. When you next want to show the form, the same data will be loaded as before, because you didn't save any changes to it.
The easy way: don't re-use form instances. Do var childForm = new MyChildForm(); before each childForm.Show();

One general context menu

I have one general context menu and for example 4 buttons and 4 textboxes - when I click on any of these buttons the context menu is opened and when I click on some items I would like to send this item to textbox, which was between button - I need to send some identificator to context menu to know which button open it and then to know where to send selected item.
How can I do that?
I am using c#
Thanks
this.ActiveControl will give you the button that has the focus. You can put the identifier in the Tag property of each button. This way, this.ActiveControl.Tag will give you the information you need.

passing data from Ajax Modal popup extender to a textbox on the asp.net page

I have a Ajax modal popup that displays a set of options for the user. On submit button click event on the ajax modal popup, i need to pass the user selected data back to a text box on the user control (which has the modal pop up) on the calling page.
Structure/flow is as follows. There is a page and two user controls. One is a search control that has another user control that contains the user options. The master page has the search user control. When the user chooses an option in a dropdownlist in the search control, it does a mpe.Show of the user control with options. User makes his selections and hit submit button. In the button click event in the popup, i delegate an event back to the search user control which tries to set the value in one of its text boxes. Everything is going fine until this step and i can see the value but the text box never changes. It seems like the user control is already rendered and the changes are ignored. Any idea how I can get around this?
In short, how to get back the data to a control from an Ajax modal popup.
Use jquery - when the user clicks a button on the modal - use jquery to set the value field to be the data that the user has selected.
e.g.
$('#modalButton').click(function() {
var userData = $('#tbUserData').val();
$('#textBoxElsewhere').val(userData);
});
for anybody's future reference, i did a work around for this. What was happening is that, on the final button click postback, the page/parent user control load events run first and then the button click event.. so the changes that were being made in the button click event did not make it back to the parent user control on the page.. i had to add a middle step to display the user selections for approval and force the user to hit a final confirmation hit. On that post back, the changes were already available for the parent user control, and not have to wait for the button click event to trigger to grab the data. I'm sure there is a better way to do this but this is what I could come up with.

Categories