Get response from web browser for windows phone 'mango' - windows-phone-7

I m my application I want to use Webbrowser which will be using Wifi,after the Webbrower opens the the link (task.URL) ,I want to check what is the response like whether the linked got opened or it failed.How do I do that means get the response ?
WebBrowserTask task = new WebBrowserTask();
task.URL = "https://www.goggle.com/";
task.Show();
kindly help
Thanks.

Usually, to catch this use NavigationFailed event as follow:
void WebPage_Loaded(object sender, RoutedEventArgs e)
{
this.webHome.Navigate(new Uri(www,UriKind.Absolute));
this.webHome.NavigationFailed += webHome_NavigationFailed;
}
void webHome_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
{
this.webHome.NavigateToString("No web page available.");
}

Related

Unable to clear cache of WebBrowser control in windows phone 8

I have used a WebBrowser control in my windows phone application. Using webbrowser control i am logging into my application. On log-out i simply redirect the user to log-in page again and trying to clear the cache and cookies of the webbrowser control.
mybrowser.ClearCookiesAsync();
mybrowser.ClearInternetCacheAsync();
instead of showing log-in screen, it get the previous credentials and logged-in into the application. Can anyone please help me in clearing the cookies and cache of webbrowser conteol.
Complete code:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
App.AccessToken = "";
myBrowser.Navigate(new Uri(login URL));
}
void Navigating(object sender, NavigatingEventArgs e)
{
if (Login complete)
{
clearCahe();
}
}
public async void clearCahe()
{
await myBrowser.ClearCookiesAsync();
await mybrowser.ClearInternetCacheAsync();
}
async functions are hard to get use to. If you put a break point at
await myBrowser.ClearCookiesAsync(); // put a break point here then step-in (F11 on the keyboard)
You will see that will not actually await and will continue on its merry way.
To fix this you have to do something like this
using System.Threading.Task;
public async Task<bool> clearCahe()
{
await myBrowser.ClearCookiesAsync();
await mybrowser.ClearInternetCacheAsync();
return true;
}
and a calling function that also async
like so
private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
await clearCache();
// then navigate the page
}

A Particular page must be opened when he user uses the windows app for the first time

I am developing a windows 7 phone app where I want a particular page( A privacy policy which the user needs to accept ) to be displayed when the user uses the app for the first time in his phone. Can any one please tell me how to get this done.
Two approaches can be taken for this functionality. The first is to always start at the privacy policy page but override the OnNavigatedTo method to check if the policy has been accepted before. If it has, navigate to your "MainPage". Within the Mainpage, remove all backstack entries.
Privacy Policy Page
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// have the accepted the policy?
var settings = IsolatedStorageSettings.ApplicationSettings;
bool accepted;
if(settings.TryGetValue("PolicyAccepted", out accepted))
{
if (accepted)
{
NavigationService.Navigate(new Uri("MainPage.xaml", UriKind.Relative));
}
}
}
private void OnAcceptButtonClick(object sender, RoutedEventArgs routedEventArgs)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
settings["PolicyAccepted"] = true;
settings.Save();
NavigationService.Navigate(new Uri("MainPage.xaml", UriKind.Relative));
}
Then in your MainPage, remove the backstack
protected override void OnNavigatedTo(NavigationEventArgs e)
{
while (NavigationService.CanGoBack) NavigationService.RemoveBackEntry();
}
The second approach is to is a UriMapper as described in this SO answer.
A possible answer to this question can be found here. As you want your page to open up only once I suggest IsolatedStorageSettings to save a boolean value if the user has accepted the policy or not.

WebClient.DownloadProgressChanged not working?

I am using Windows Phone to download a file with a WebClient. The DownloadProgressChanged event does not work. It fires only once, returning a value of "4923206" for DownloadProgressChangedEventArgs.BytesRecieved. My code is:
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
WebClient wb = new WebClient();
wb.DownloadProgressChanged += wbchange;
wb.OpenReadAsync(new Uri("http://sohowww.nascom.nasa.gov/data/LATEST/current_eit_304small.gif"));
}
private void wbchange(object sender, DownloadProgressChangedEventArgs e)
{
MessageBox.Show(e.BytesReceived.ToString()); (obviously in the end I will not be showing a message at every change)
}
What is wrong with this?
It's working absolutely fine, it just happens to have downloaded all the bytes on the first DownloadProgressChanged invoke.
If you read the documentation you'll see that this is the expected behaviour.

Not able to insert data into remote mySQL Database using PHP

I am trying to insert data into remote MySQL database using WP7 app but values does not get inserted, PHP file works perfect as my queries are getting inserted into DB using JAVA(Android). As I am new to C# I am facing this challenge.
The code goes like this:-
public MainPage()
{
InitializeComponent();
textBox1.Text = "http://www.abc.com/xyz/user_master.php?Email=abc#xyz.com&Username=abc&Password=xyzz&Phone=98989";
client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
textBlock2.Text = e.Result;
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
client.DownloadStringAsync(new Uri(textBox1.Text));
}
Please correct me.
The problem is that you are using "DownloadStringAsync" which sends a GET and so you POST variable is not filled in PHP, you have to use "UploadStringAsync".
For now I can not tell you how the body has to look like... Until now I have used JSON all the time. Would be nice if you could post it here to let me know when you got it ;)
update
Ah, to slow =(
Could you please still post how your message body looks like!

Passing (Asp.Net) Session variable (uploaded by uploadify) from webmethod to same page?

When i try to get uploaded filename from generic handler (upload.ashx) using session its ok, no problem. I can also use webmethod on samepage and uploadify works great, but Session["fileName"] is getting null. Is there anything wrong on my code? Do i only need to use generic handler to get filename?
[WebMethod(EnableSession = true)]
public void LoadPicture(HttpContext context)
{
try
{
HttpPostedFile file = context.Request.Files["Filedata"];
context.Session["fileName"] = file.FileName;
....................Some resize and save image codes.........
context.Response.Write("1");
}
catch (Exception ex)
{
context.Response.Write("0");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
using (_modelService = new ModelService())
{
ModelEntity _models = new ModelEntity();
......some codes....
_models.modelphoto = Session["fileName"].ToString();
_modelService.ModelAdd(_models);
}
}
Uploadify uses Flash. Flash doesn't send cookies. In ASP.NET sessions are tracked by cookies. So, no session with uploadify, sorry.

Resources