how to show main method exception message on mvc view page? - asp.net-mvc-3

In my project I have use main method implementation for saving values from excel sheet to database. Now, I have to show main method exception message on view page where I have designed an interface to upload excel sheet and a button. Please help me....

You could perform your error handling by overriding Application_Error in global.asax.cs. That way you can be sure that your code will only execute when an error occurs. In here you could put a redirect to a ErrorPage.cshtml page
Here's the function:
void Application_Error(object sender, EventArgs e)
{
//do your stuff here
}

Related

How to save the information on a Page when traveling from one detail page to another

I am working with Xamarin.Forms and I am trying to implement my multipage form in a Master-Detail format. When I click on another page from the Master page menu, I want to make sure that the information on the current detail page gets saved to its respective database table on the mobile device before I travel to the next detail page. Any idea on how to achieve that?
Have you looked at the OnDisappearing() method?
protected override void OnDisappearing()
{
//Your code before you switch to another page
}
Hi #lovetolearn you can achieve this things OnDisappearing() method of each page.
protected override void OnDisappearing()
{
//Your code before you switch to another page
}

Why does attempting to show a ViewModel throw an unhandled exception?

I'm using Visual Studio 2013 and MvvmCross to create an Android application using Portable Class Libraries. When I try and load a second ViewModel based on an action in the first View, an Unhandled Exception is being thrown.
In my first ViewModel, CatalogViewModel, I've got an ICommand called ShowCamera that is supposed to display the second ViewModel, CameraViewModel, when a button in the CatalogView is clicked.
In CatalogView.axml I've bound the button to the ShowCamera method in CatalogViewModel.
Right now the CameraViewModel is just an empty class but it inherits from MvxViewModel just like CatalogViewModel
And there's also a corresponding CameraView.cs and CameraView.axml.
Has anyone else ever encountered this or have any idea why the exception is being thrown. I've tried using a try/catch in the Get to see if I can get any more specific info about the unhandled exception without any luck (the catch block is never hit, the exception is always thrown on the ShowViewModel line).
Thanks in advance.
As Stuart pointed out it his comment, it was the lack of an [Activity] attribute on CameraView that was throwing the exception. The class definition for CameraView should be.
[Activity(Label="View for CameraViewModel")]
public class CameraView : MvxActivity
{
...
}
instead of
public class CameraView : MvxActivity
{
...
}
I initially thought about deleting the whole question out of embarrassment but decided to answer it and leave it here for anyone else who might encounter this situation in their own code.

why getting null refence exception when giving iconuri in application bar?

in application bar firstly i given some images.when click on that icon need to assign new image.for that in click event wrote the bellow code.
private void searchbtn_Click(object sender, EventArgs e)
{
searchbtn.IconUri = new Uri("/Images/settings_high.png", UriKind.RelativeOrAbsolute);
}
Getting NULL Refernce exception.please help me
In case you did not know (I didn't) you must set the image Build Action property to Content, not resource. Then you can access the file like this:
StreamResourceInfo resourceInfo = Application.GetResourceStream(new System.Uri("ima1.png", UriKind.Relative));
If the stack trace shows a NullReferenceException directly in your method, that suggests that searchbtn is null.
I suggest you put a breakpoint on that line of code and run it in the debugger, then use the Auto window to check the value of searchbtn.
Is it possible that you've declared your own searchbtn variable while there's another similarly-named variable which actually has a reference to a button? The event handler name would suggest otherwise, but it's at least worth checking.
If the stack trace shows a NullReferenceException deeper in the code, that suggests there's a different problem. If you could post the full stack trace, that would help.

Remove a page from Navigation Stack

I have this application schema :
[List Page] -> [Detail Page] -> [ShareOnFacebook Page]
^__________________|
The user select an Item in the [List Page]
The user may or may not click a Share button if he or she does, the application navigates to a [ShareOneFacebook page] which displays a Facebook Login Form, posts a message and navigates back
The user navigates back.
If the user shared on facebook, it will "repost" the message, because the application store the session so it will navigate back to ShareOnFacebook, and then back to my Detail page.
If the user didn't share, he goes back to the List Page.
How can I "ommit" the ShareOnFacebook page in my navigation stack ?
Try this: Call NavigationService.RemoveBackEntry(); in the OnNavigatedTo method. This will remove the previous page from the stack. In my opinion the trick with Navigation.GoBack(); is not satisfying because it shows the page to remove for a short time.
Note: Works only with Windows Phone OS 7.1 (Mango) SDK
I have a similar situation in my app, i solve it with a very simple solution.
If you want to "skip" a page in your backstack, place some logic in the NavigatedTo() function of that page.
For example: you can have a bool that you set to true when you post to facebook, and then place the following code in the NavigatedTo() function of the ShareOnFacebook page.
Here is pseudo code:
if (alreadyPosted)
Navigation.GoBack();
The GoBack() function will skip this page and return to the previous one, the user will never see the page.
Have a look at simple library i wrote for such purposes:
http://navcoerce.codeplex.com/
var fluent = new FluentNavigation(RootFrame);
fluent.WhenNavigatedTo<MainPage>()
.ThenTo<LoginPage>()
.ThenToAnyPage()
.RemoveEntriesFromBackStack(1);
fluent.WhenNavigatedTo<MainPage>()
.ThenTo<LoginPage>()
.ThenTo<RegisterPage>()
.ThenTo<PaymentPage>()
.RemoveEntriesFromBackStackTill<MainPage>();
fluent.WhenNavigatedTo<MainPage>()
.ThenTo<SecondPage>()
.ThenTo<RegisterPage>()
.ThenOptionallyTo<ForgotPasswordPage>()
.ThenToAnyPage()
.RemoveEntriesFromBackStackTill<MainPage>();
fluent.WhenNavigatingTo<PaymentPage>()
.RedirectTo<LoginPage>();
fluent.WhenNavigatingTo<PaymentPage>()
.If(() => false)
.RedirectWithReturnUri<LoginPage>("ReturnUri");
Have a look at the new Nonlinear Navigation Service recipe
Download it from http://create.msdn.com/en-us/education/catalog/article/nln-serv-wp7
I use the removeBackEntry method on the NavigationService Class. I also use this as a way to setup my own splash screens
private void BWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// switch screen
NavigationService.Navigated += new NavigatedEventHandler(NavigationServiceNavigated);
NavigationService.Navigate(new Uri("/Pages/main.xaml", UriKind.Relative));
}
void NavigationServiceNavigated(object sender, NavigationEventArgs e)
{
NavigationService.RemoveBackEntry();
}
I posted an example for the same issue here.
The Nonlinear Navigation Service Matt linked to essentially does the same thing but would probably be better than my simple example.

SharePoint Webparts and Ajax

Please, I am new to webparts and I need help!!
I have a custom web part that I created. I added MS Ajax to it using an UpdatePanel which works fine. I add all my controls to the CreateChildControls method. As soon as I add a UpdateProgress control my page breaks with the following error:
Script controls may not be registered before PreRender
I do not use the OnPreRender event as what other posts suggest. Please, if anyone can give me advice it will be very much appreciated.
Thanks
I encountered similar problem before, try to call EnsureChildControls method inside your on init method override. It should be called by system automatically, but sharepoint likes to forget about it from time to time.
Like this:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
EnsureChildControls();
}
You might have forgotten to call the base method of an overrided event, which is not necessarily the OnPreRender event.
Check if the OnInit or OnLoad events are calling their base.On[...] method, e.g.:
protected override void OnLoad(EventArgs eventArgs)
{
base.OnLoad(eventArgs);
// your code...
}

Resources