MessageBox appears but does not pop up - c#

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

Related

Click "Send" button of G-Mail programmatically

I am creating an Email Sending Software. So far i am able to open chrome and fill the details of the email (subject,body,attachments and all) but i wanted to know is there any way i can click Send button of G-Mail programmatically too?
Code for filling details in chrome
Process ps = Process.Start("chrome.exe", "https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=1&to=a#gmail.com&bcc=b#gmail.com);
Note I haven't used SmtpClient to send email because it was not fulfilling my customized requirement (sorry cannot disclose the reason).
The way you want this, is not possible. Process.Start opens a new Process. In this case it opens Google Chrome, with the URL you sent with it. This URL contains a querystring containing the subject and the body of the email. This is possible, because Google reads this on the server-side, and puts it in the right fields. There is no way to enter the send button though. This is a POST action, which can not be triggered by a URL.
C# form, does have a WebBrowser class. From here you can access buttons and click them, but I don't think Google will allow this, and most likely send you a captcha. (That is, if you manage to login in the first place.)
I can't help with the simulated button press you're looking for, but I can suggest that you rather try to use the Gmail API to do what you're trying to do:
https://developers.google.com/gmail/api/?hl=en
This would be a more reliable and stable way to send gmail programmatically, and you still don't have to use the smtp object directly.
You should probably use Selenium (WebDriver). It allows you to control browser from c# code, navigates pages, traversing DOM etc..

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

flickering of popup window

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().

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