This topic is locked

How to redirect user to the View page when search returns a single record

3/27/2020 3:15:06 PM
ASPRunner.NET Tips and tricks
admin

If our search returns a single record we may want to save our users a mouse click and send them directly to the View page of that record. To do so add the following code to BeforeDisplay event of the List page in question:

if (pageObject.numRowsFromSQL.ToString()=="1" && MVCFunctions.postvalue("a")!="return") {

dynamic id = pageObject.controlsMap["gridRows"][0]["keys"][0];

dynamic tName = pageObject.shortTableName;

dynamic link = MVCFunctions.GetLocalLink(tName,"view","editid1="+id.ToString());

MVCFunctions.HeaderRedirect(link);

MVCFunctions.Exit();

}
Pete K 3/28/2020

Thanks for that great tip, Sergey. This is just what I need for an upcoming project where the client specified that they wanted the user to be able to use type-ahead in a search box to go straight to the target page.

T
tetter 4/14/2020

Hi Sergey,
I think the condition should be extended by ' && pageObject.masterKeysReq.ToString() == "" ' in order to avoid a redirect to the view-page when the list page is part of a linked master/detail list-page.
If there is a better way to avoid this, I'd be ready to listen.
Rgs TomE