flickering of popup window - c#

below is my code which closes popup window on page load also i want to show the user a message box plz login well my popup window gets close but it flickers on the screen is there any way to prevent to do that.
StringBuilder sb = new StringBuilder();
sb.Append("<script>");
sb.Append("window.close();");
sb.Append("</script");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "test", sb.ToString(), false);
MessageBox.Show("Please Sign In first...", "Login Message", MessageBoxButtons.OK, MessageBoxIcon.Question);
return;

Your code makes no sense. You're calling RegisterClientScriptBlock, so evidently you're using ASP.NET WebForms. But you're also trying to call MessageBox.Show (looks like the WinForms version). You had to go out of your way to use both those frameworks from the same code base, and there's a reason for that: they're not meant to work together.
If you're using ASP.NET, that means your C# code is running as a Windows service on the Web server machine. That means that, if a user visits your Web site, you'll try to show a dialog box on the server machine (which is in some locked server room somewhere). The visitor to your site won't see a thing on their computer. Actually, since IIS runs as a non-interactive service, I think the call to MessageBox.Show will simply be ignored.
The only code that will run on the visitor's machine is the HTML and JavaScript produced by your ASP.NET page. If you want to show a dialog box to the user, you need to use JavaScript. The simplest way is by calling window.alert().

Related

MessageBox appears but does not pop up

I have a message box that has ok or cancel as options to ensure the user wishes to change the name of a company. However, this message box doesn't pop up on the current screen, instead it just appears on the windows task bar and blinks there.
May I know how do I make it appear?
var ConfirmResult = MessageBox.Show("Are you sure you want to change the name of the Company?", "Confirm Update!", MessageBoxButtons.OKCancel);
edit: This is in asp.net web forms.
You must understand and distinct the programs that runs on desktop, and the programs that runs on server and send the results to some web browser.
In this case the MessageBox, is creates new window on the desktop side – is not work for a web application, not make sense at all.
To make a message box in a browser, you need to think different – you make the message box using some css and javascript and you render that on the page on the browser.You handle the events with javascript and/or post back
get some ideas: https://www.w3schools.com/howto/howto_js_alert.asp

How to Insert Confirm Dialog Between Forms.Authentication and ReturnUrl?

I am revamping the authentication system of an ASP.net webforms application (which relies on Forms.Authentication) to limit each user to a single browser session. To support this, I have created a new IHttpModule which uses an application variable to maintain a dictionary that maps userId to sessions, patterned after this article.
All of that is working great, but there is one more component that we want to add: an ok/cancel dialog displayed after login is successful, warning the user that their first session will be closed if they proceed. If they choose to cancel, then we need to interrupt the login process without sending the user to the returnUrl set via Forms.Authentication.
So far, my attempts have been around adding this to the loggedIn event, where the sessionId is captured and compared, however my attempts at stopping things once this point occurs have not worked out -- the user is redirected past my confirm dialog without anything actually firing.
Thus the question: How can I insert a confirm dialog to the login process of Authentication.Forms?
Something you might try - make the form auth an ajax call, then handle your dialog on the client side. So, for example, intercept the login form post using jquery, do an ajax post of the login form, get json or something else back, and then pop the dialog with a redirect on the client side.

Facebook Desktop Auth pop up Browser

I'm writing a desktop app in C# that has Facebook integration and I'm trying to figure out how to do authentication/login. I have thought of two different approaches:
1. Popup default browser
The user probably is logged into Facebook on their default browser.
Code: System.Diagnostics.Process.Start("http://www.facebook.com/...");
Issues/Questions: How do I control the window location and size (e.g. not show address bar when it starts)? Can I destroy the process after login is complete or even close the window (won't most browsers prompt for window closing if done from javascript?)?
2. Popup specific browser
If I lookup the default browser, I can pass command-line flags to the browser. "..\chrome.exe" --app=http://www.facebook.com/...
Questions: How do I set the window size/location? How do I close the process after login-complete (assuming I know when the login is complete)?
Is there a better way to do this?
very usefull resource in this situation is http://facebooksdk.net/.
Earlier, there was a sample project for desktop application on facebooksdk.net, but it was removed. You can see it here https://github.com/MarkAureliy/facebook-winforms-sample-master
This project is straight for your needs

how to notify webserver when user closes the browser (in asp.net)?

I am developing a relay chat application , divided into 2 panes.
right pane - > The Chat responses of users (this uses a ASP.NET Multiline Label control placed inside the update panel , so when any user types the responses and submits it is added to this control)
left panes -> the list of users currently online(this uses ASP.NET list control which is also placed inside the update panel).
below this is the textbox for the user to enter text and a send button to post his response.
everything works fine. But when user closes the browser window instead of clicking the log out button. the list on the left pane is not getting refreshed.
It happens properly , when the user logs out.
IS there any way to knock of the users name from the list if the user closes the browser?(even before his session is expired on the server side).?
sorry i couldn expose the screen shot.
can any one suggest an idea along with a sample code snippet.?
thanks
vijay
You can do it the other way around: ping the server from the browser with an ajax call periodically. If no ping received, remove the user.
You can use Javascript to detect when the browser has been closed, and then kick-off an AJAX request back to the server notifying that the user left.

How to launch a browser and later direct it to a page?

I need to launch a browser, do some work and then make the browser navigate to a URL (in that order).
The first part is of course simple and I have a Process object. I am at a loss as to how to later direct it to the target page?
How do I treat the Process as a browser and make it navigate to the desired page?
Any help, pointers, code snippets appreciated.
Instead of launching the browser & then navigating to the page, just tell the OS that you want to run the URL. Windows will pick the correct browser, and navigate the user to the given URL.
System.Diagnostics.Process.Start("http://www.StackOverflow.com");
If you don't need to do this in production, you could use a testing library such as WatiN to do this:
using WatiN.Core;
//Placeholder page to launch initial browser
IE ie = new IE("http://www.google.com");
DoSomeWork();
//Now navigate to the page you want
ie.GoTo("http://stackoverflow.com");
My first instinct for this question was DDE, but it appears that has been decommissioned in Windows Vista so that is no good. Shame, as it was the only consistent mechanism in Windows for Interprocess Communication (IPC)...oh how I miss Arexx on the Amiga.
Anyhow, I believe the following will work but unfortunately, due to the way it works, it launches Internet Explorer irrespective of the configured browser.
If your application has a Form, then create a WebBrowser control on it. Set this to non-visible as we are only making use of its as a launching device rather than to display the web page.
In code, at the point where you want to show a web page, use the following code:
webBrowser1.DocumentText = "window.open('How to launch a browser and later direct it to a page?', 'BananasAreOhSoYummy');";
What this does is to tell the WebBrowser control, which is just the IE in disguise, to open a new window called 'BananasAreOhSoYummy'. Because we have given the window a name, we can use that line repeatedly, with different URLs, to change the page in that particular browser window. (A new window will be opened if the user has happened to close it.)
I will have a think about an approach that honours the user's default browser choice.
If you don't need the actual instance of IE, you can use the System.Windows.Forms.WebBrowser control.
I think instead of sending the browser a url you could send it javascript that would run and direct the browser to a site.
Not sure if this would work but I see no reason why it wouldn't

Categories

Resources