What happen during processing - asp.net

Maybe this is a dummy question, This is the scene.
I've got a web system (ASP.NET MVC 2.0). When I press the "Save" button all the process it's call and begin the execution. What happen if I:
1) Press another link to change view
2) Press again the submit button
Both scenes whereas the process not finish yet.
Regards.

The first controller (that handles the button) probably got the action, and then another controller got an action (from the link, if it's to the same site), and then the first controller gets the button action again.
your browser aborts the calls, but they are run in the server.
eventually the browser shows you the last result from the call that was not aborted.
If you want to observe this behavior use a debugger - and see the actions called.. and firebug - to see the browser aborts...

Related

Create dialog confirm in server site ASP.NET

I want to create a dialog confirm in ASP.NET.
I'm doing it with this code:
protected void Button1_Click(object sender, EventArgs e)
{
ClientScriptManager CSM = Page.ClientScript;
string strconfirm = "<script>if(!window.confirm('Are you sure?')){window.location.href='Default.aspx'}</script>";
CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
if (the condition to yes clicked)
{
// do something ....
}
else
{
// do something else ....
}
}
How can I get the yes / no condition in this case?
Thanks for reading my post
You can't do it this way. Your code behind NEVER interacts with the user. Your code behind ONLY interacts with the web page, and ONLY does so WHILE the page is making the round trip.
Before a post back? You have this setup:
You do NOT have this:
And you do not have this either:
So, when a user clicks a button - this occurs CLIENT side. The page - whole web page is sent up to the server - and THEN your code interacts with the web page - NOT the user!!!
so, you click on a button - (browser). The page THEN starts the all important round trip. Like this:
the page travels up to server,
You now have this:
Now and THEN your code behind runs. When done, your code behind MUST finish, else the page stays stuck up on the server side. When done, the whole page page makes the trip down back to the browser. And THEN the page is re-displayed and THEN any js code can run.
So when done? Your page makes the trip back down to the browser like this:
And only AFTER the page makes that trip, can the browser display what your code behind changed. So your code behind NEVER interacts with the user, but in fact can ONLY interact with the web page and ONLY do so for the short time that the web page is up on the server.
So, how can you pop a dialog and get a yes/no answer? Well, you require the dialog to run and launched client side. And based on the user hitting ok, or cancel, you can THEN have a code stub run.
So you can say have code that flows like this:
ClientScriptManager CSM = Page.ClientScript;
string strconfirm = "<script>if(!window.confirm('Are you sure?')){window.location.href='Default.aspx'}</script>";
CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
Function OkCode - runs on user click or seleciton.
Function Cancel Code - runs on user click of cancel button.
So, you need 3 code stubs. One to inject the script that will pop the dialog. And then the ok or cancel button in that script/dialog can THEN launch the server side code again. This will of course require that round trip (as all server side button event code does).
There are a few short cuts. Say I have a standard asp.net button, and I want a confirm dialog? Well, you can do this:
<asp:Button ID="Button1" runat="server" Text="Delete"
OnClientClick="return confirm('Delete record');"/>
The above works, since the confrim in js returns true or false and that will prevent the button code (code behind server side) from running.
You could of course have a script that you call from code behind. Keep in mind that your register script quite much has to be the LAST thing you do and inject into that page before it travels back down to the client. The page dispays and THEN your script you added THEN runs!
You could say then have two buttons on your form - hide them. And then have a js dialog that clicks either button based on what you pass.
So, say we build that function. We will pass it the question/text, and then say two buttons (one for ok click, and one for cancel click). And you could set the style of those buttons as display:none. This will still not get you a server side if/then result from that dialog. So, you have to quite much in near ALL cases break your code out to 3 seperate parts.
The part that triggers the dialog.
And the two buttons that run code behind stubs based on the choice(s) the user makes. In other words, adding the dialog by script would STILL require you to have TWO separate code stubs behind to run (the one for ok, and the one for cancel). You simply can't pop a dialog server side and wait. That would result in the web page being stuck up on the server in the above round trip concept. That round trip dialog MUST be absorbed into your mind - without that model of how the round trip works, then you make mistakes in your design assumptions - and thus your question which is actually not really possible to achieve.
You could create a generalized dialog that you set the text in code behind along with your register script idea. but the button choices and code it runs would also have to be setup in that register script, and you would still require two separate code behind stubs (one for cancel, and one for ok). So it would be possible to setup something that requires you to NOT have special code in each page, but you would require a js function routine you build up, and you would have to supply it the name of the two code stubs, and then that js routine could send a __DoPostBack passing the choice made.
But even again, note how you need separate routines, since that web page is sitting on the users desktop, and your code behind is not waiting for a dialog, but in fact a WHOLE PAGE post back.
So just keep mind that code behind does not interact with the user - it ONLY interacts with the web page, and ONLY does so during that short round trip and in fact ONLY during the time that the web page is up on the server, and your code behind runs and then is finished. And THEN the web page starts that trip back to the client side - the page is re-loaded, changes you made are displayed, and THEN the js in that page starts to run again.

DeviceMotionEvent.requestPermission() throws NotAllowedError

I have a web page that I'm loading in Safari on iOS 13.4.1. The web page calls DeviceOrientationEvent.requestPermission() and in the .catch following the .then I'm seeing this error:
NotAllowedError: Requesting device orientation or motion access requires a user gesture to prompt
However there is no pop-up requesting permission.
Does anyone know what I'm missing?
Late reply, hoping it might be useful to others.
The call DeviceOrientationEvent.requestPermission() in your code must be performed as a reaction to some user gesture.
So e.g. you would show a dialog to user with a message and a button, explaining what's going to happen next. In button click handler, you hide the dialog and actually call that method.
An example of click handler is given here: https://dev.to/li/how-to-requestpermission-for-devicemotion-and-deviceorientation-events-in-ios-13-46g2 .

MeteorJS perform action when window closes

I want to perform an action when the user closes their browser.
I have tried use https://github.com/mizzao/meteor-user-status hooks. Mainly the UserStatus.events.on('connectionLogout') but this event gets fired when you refresh the page.
I also tried window.beforeunload but that too also gets called on every page refresh.
Is there something that allows me to perform an action when someone closes a browser?
So for clarification you want something to happen when the entire browser closes-- I exit my chrome browser?
Or when I leave your page?
Or when I close the tab/window in which your page was contained? (But browser is still running with other pages)

how to intercept processing when Session.IsNewSession is true

I have a small 4-page application for my customers to work through. They fill out information. If they let it sit too long, and the Session timeout out, I want to pop up a javascript alert that their session has expired, and that they need to start over. At that point, then redirected to the beginning page of the application.
I'm getting some strange behavior. I'm stepping through code, forcing my Sessioni.IsNewSession to be true. At this point, I write out a call to Javascript to a Literal Control placed at the bottom of the . The javascript is called, and the redirection occurs.
However, what is happening is.. I am pressing a button which is more or less a "Next Page" button and triggering this code. The next page is being displayed, and then the Alert and redirection occurs. The result I was expecting was to stay on the same page I received the "Timeout", with the alert to pop-up over it, then redirection.
I'm checking for Session.IsNewSession in a BaseClass for these pages, overriding the OnInit event.
Any ideas why I am getting this behavior?
Thanks!
There multiple ways u can do this. Have hava Script timer as per u session timeout (Default is 20 min). After 19 min just rasise a alert on client and submit the page to the same page to refresh. This may not good option given user would have entered lot of stuff already
Or other way is don't session time out this page. U can do this on back ground just refresh the page after 19 min (U can do this by placing one div and iframe or image request on the server.). This might be good experiance for the user the reason is he don't have to enter the content again. Talking to u client giving this kind of option is worth sometimes.

Please wait dialog & downloading files in asp.net

In my ASP.Net application I have a requirement that when a user clicks on an UI element we generate a PDF for them which they can download. This is currently implemented by doing a form post to an ashx page. This page essentially inspects the form and then executes the correct server side page which either results in HTML or a PDF document of that pages HTML.
On the client I know ahead of time if we are going to be getting a PDF or HTML, when its an HTML I open a new window and direct the form post to that window and all works well. When its a PDF I don't change the target for the form and it remains on the current page.
This works, the user is presented with a save dialog, and the current page is not changed or lost.
The problem I have is that generating the PDF takes anywhere from 1-15 seconds. What I want to do is popup a please wait dialog. Displaying the popup is going to be easy, what I am not sure of is how do I know to close the popup? The popup will be a div in the current page.
The popup can have a client side timer which polls the server for task completion. The long running server task should update the progress in a database table or a server cache object which can be accessed by the polling service.
Couple of old articles from MSDN magazine. You should be able to use the same concepts with newer libraries like asp.net Ajax.
Reporting Task Progress With ASP.NET 2.0
Simplify Task Progress with ASP.NET "Atlas"
just have some javascript on the client side and let it show some animated GIF for 1-15 seconds (your choice) and close itself after the designated time.
Gulzar's suggestion was spot on. I have a simple ajax enabled wcf service which checks a session variable. My ashx page sets the variable to false when it starts processing and then true when its done.
I think there might be a race condition if the client checks before we set the session item to false; however, there are ways around that if we modify the service to set the session item to false after a client gets an im done response.
The tricks is still going to be figuring out what the intervalon the client should be. If we set it to low the user could save the file and then see the still processing message. I'm debating myself between half a second and a second. Anything less then a half a second seems unnessecary.
You said:
When its a PDF I don't change the
target for the form and it remains on
the current page.
If that is the case then the original page will be gone when the PDF is opened. In that situation I would have a loading animated gif and open it using Javascript into a div tag overlaying the rest of the page. You would not need to close it, so no timer or polling needed. It would just be gone when the page is gone.

Resources