Forums: [SOLVED] Change behavior of view page when record not found - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

[SOLVED] Change behavior of view page when record not found Rate Topic: -----

#1 User is offline   Pete K 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 224
  • Joined: 05-February 16

Posted 01 March 2018 - 08:11 PM

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?





----------------------------------------------------------
Pete K.
Web Developer
Fayette County Public Schools | Lexington, Kentucky, USA
0

#2 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 15889
  • Joined: 03-February 03

Posted 01 March 2018 - 10:26 PM

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.
Best regards,
Sergey Kornilov
0

#3 User is offline   Pete K 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 224
  • Joined: 05-February 16

Posted 05 March 2018 - 01:11 PM

View Postadmin, on 01 March 2018 - 05:26 PM, said:

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.


----------------------------------------------------------
Pete K.
Web Developer
Fayette County Public Schools | Lexington, Kentucky, USA
0

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked