This topic is locked
[SOLVED]

 Change behavior of view page when record not found

3/1/2018 3:11:16 PM
ASPRunner.NET General questions
Pete K author

I have a situation where it is possible (due to complicated factors) that a user of my app may attempt to open a record in a view page when the record called actually does not exist. The baked-in behavior when this occurs is the application redirects to the list page. This makes sense under normal circumstances, but in my case it just causes confusion.
What I want to happen instead is redirect the user to a different page. The problem is I'm struggling with how to code that and if there is even an event available where it would work. Ideally, I would need to be able to insert my code after the SQL is run but before the page is displayed. I have tried placing the following code in both the BeforeShowView() and ProcessValuesView() events with no luck. I think that either my test for missing page id isn't working, or the redirect occurs within the base code before these events fire.
Here's my code:



// Try to redirect to notopic page rather than list page if current page not found

string pageID = values["Page"].ToString();

if (string.IsNullOrEmpty(pageID))

{

MVCFunctions.HeaderRedirect("page","view","editid1=notopic");

}


Any ideas?

admin 3/1/2018

You should place your code to View page BeforeProcess event. In that event read "editid1" parameter from the URL, run SQL query to see if this record exists and if it doesn't redirect user to another view page.

Pete K author 3/5/2018



You should place your code to View page BeforeProcess event. In that event read "editid1" parameter from the URL, run SQL query to see if this record exists and if it doesn't redirect user to another view page.


Thanks Sergey. I was hoping to be able to do it without running another SQL query, but this will work.