Asp.net force save on detailsview/formview - c#

When a user is using a Detailsview or Formview in Edit mode, and tries to leave the current page, I want to trap this and force any changes to be saved, just as if the user had clicked on the Update LinkButton. How can I do this?

You can't do this reliably. Consider the scenario if their computer crashes altogether, or they kick the power cord out. There's so many ways that a user can leave a page.
However, you could put in a few safeguards. On any link on the page you could hook up events to do the save before they left. You could also try doing a save after every change in control focus perhaps.
Another thing you can do is hook into the window.onbeforeunload event and give them a confirmation message asking if they're sure they want to leave the page, like SO does when you have an unsaved answer. But there's nothing you can do with this event to force a save.

Related

InvokeMember("Click") as it come in div

in webbrowser control a booking website. when i search A To B it give list of items with price. (price is a radio button) when i click radio button. a new div created after some process a submit button named "submitButton0" comes on webpage. on same web page. website location not changed. i want to invoke click of submitButton0.
problem is that. webBrowser1_DocumentCompleted Event has been done. but that time submitButton0 not in page. pragmatically readio button has been click. after some process a submitButton0 comes on page. as submitButton0 comes i want to invoke its click quickly.
what is the solution of it?
but that time submitButton0 not in page
Which probably means that the buttons are added by Javascript. There's no way to synchronize with script execution, you need to poll. Enable a timer in the DocumentCompleted event handler and in the Tick event check if the DOM was changed enough to allow calling InvokeClick() reliably.
Do check if the site owner makes a web service available. The fact that buttons get added later is a fairly strong hint that the site's TOU does not permit automation. And a service makes your app much more resilient to web page changes. The DOM polling trick is pretty much guaranteed to break sooner or later.

Save page data when leaving page

I have an edit form that that has 2 buttons on it, 'Save' (duh) and 'Return To List' ( which performs a save before actually returning ). The problem is the page also has Side Navigation and Top Navigation. So when the user selects any link in those the page doesn't save. Is there a way to perform a save even when Side or Top Navigation links are selected?
Note, this is an MVC3 C# project.
Have you thought about just alerting the user the page hasn't saved yet? Use the onbeforeunload event, display an alert message (or something similar). If they want to save, have them click cancel to stay on the page and save, otherwise proceed without saving.

AjaxFileUpload hide upload button and handle manually the upload?

I want to use AjaxFileUpload control:
I am reviewing this, and the functionality I need is to hide the upload button, and save all buttons from another button click event.
Is it possible to do?
According to the properties they show, I dont see an option to hide the button.
Looking at the source html, it seems that doing:
$('.ajax__fileupload_uploadbutton').hide();
Will do the trick of hiding the Upload button. The problem remains, though, as to whether an event is triggered when the user drops the first file or selects it via the Select button. I am sure there's one you can hook into to just call the above line of code (using jQuery on my example).
You can implement the same with pure Javascript.

How to detect the close event of MMC 3.0 SnapIn written in C#

Folks, I am creating a MMC3.0 SnapIn program with C#. There I have some scope nodes and I have FormViewDescription's where I used C# UserControl instances to display some data. And my intent is, user must see and update those data into the UserControl and there is a Save button onto that UserControl which user should press at the end of their editing and I will persist that change then.
Now the problem is,
If after making some changes, user closes the SnapIn window, all his changes are gone :( I need to prevent user before closing this window with a dialog that "Save before quiting " (or something like that - you know the standard feature of any editor program).
But could not found a way to do so. Any suggestions for me?
Would be appreciated much!
Coincidentally, I have also just created an MMC in much the same manner as you described above but after much searching (and frustration) I could not find any way to cancel the close event. I recommend changing your approach as explained below.
First of all have a look at how most of the MMC's that are already in Windows handle changing settings. Usually if you want to change a setting you select an item in a ListView and right-click 'Properties' to bring up a settings form and make your changes there.
Bringing up a form gives the developer the ability to control the full lifecycle of the form and ensure that settings are saved before it is closed.
So my advice is:
Create your FormView
Add any status information you need
Add a button 'Edit Settings' to your
FormView
Create a Windows Form with
Save/Cancel + all your data input
controls
Launch your form with
myForm.ShowDialog() when you click your 'Edit Settings' button
Handle the Save/Cancel button
presses and cancel appropriately if
data is dirty
I hope this helps. Good luck!

In C# .NET 2.0, is there any way to get access to the URL history of a WebBrowser control?

Well, the title is pretty much the whole question. I'd like to be able to clear the WebBrowser controls history on every Navigate - to prevent my users from going back to a previous page. i already disabled the right click menu so they don't have access to the "Back" option, but they could still hit Backspace to go back in history. blocking the backspace key pres would cause problems when a user is legitimately using it to delete characters in web forms and such, so i figure just clearing out the history each time i navigate would completely solve the problem
EDIT: alternatively, if there is a way to detect if the Backspace key is currently pressed, i can add a check inside my handler on Navigating and cancel the event if the key is down. Too bad .NET 2.0 doesn't have the Keyboard class :(
It might be easier and more robust to use the Navigating event to cancel a page navigation you don't want to allow.

Categories