This topic is locked

Open a url in a new window or tab after record added

5/23/2018 3:40:09 AM
ASPRunner.NET General questions
C
ccvvccc author

My aim is to open a url on a new tab on After Record Added" event.
I am successfully redirecting to an external url with MVCFunctions.HeaderRedirect("www.google.com";); But it opens in the same window.
Does anybody have an idea about how to achieve this?

Pete K 5/23/2018



[color="#1C2837"]
[color="#1C2837"][font="arial, verdana, tahoma, sans-serif"]
[color="#1C2837"]

admin 5/23/2018

There are two problems here.

  1. You cannot do this in a server side event. Event happens on the web server while browser runs on a client machine. You can only do something like this using Javascript.
  2. You can use window.open in Javascript in order to do that but you cannot control if it will open a new window or a new tab since this is an end user preference. More info:

    https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript

C
ccvvccc author 5/23/2018



There are two problems here.

  1. You cannot do this in a server side event. Event happens on the web server while browser runs on a client machine. You can only do something like this using Javascript.
  2. You can use window.open in Javascript in order to do that but you cannot control if it will open a new window or a new tab since this is an end user preference. More info:

    https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript


Ok,thank you for ur answers.
How can I use window.open javascript code on afterrecord added event?

admin 5/24/2018

I'll try to explain how you can make it work. You still cannot use any Javascript code in AfterAdd event. Javascript only works in Javascript OnLoad event that is executed on the client side.

  1. In AfterAdd event set a session variable that would indicate you need to open a new browser tab/window
  2. Pass that session variable to Javascript:

    https://xlinesoft.com/asprunnernet/docs/setproxyvalue.htm
  3. Based on that variable passed to Javacript in Javascript OnLoad event you either issue window.open() or not.
    This way it will work.

H
heilmanmd 6/25/2018

For info this is working for me in ASP Runner NET ver 9.8
i.e. I'm redirecting from an Afer record updated event on an Edit Page
What I have found out is that I had to provide the "whole" path i.e. http://yada.yada.com/etc.. etc.. etc..
string iiswrkdir = XSession.Session["iiswrkdir"].ToString();

string urlval = XSession.Session["urlval"].ToString();
string httpstr= urlval + "/reports/reports.asp?rptsp=sp_est_vs_actual&who=" +

XSession.Session["userid"].ToString() + "&regdir=" + XSession.Session["iiswrkdir"].ToString() +

"&rptpage=EBGEONET_ESTVSACTUAL_RPT/list" ;
yes I'm calling an ASP page with various parameters from an ASP Runner .NET page..
MVCFunctions.HeaderRedirect(httpstr);
go figure.. sorry about that, but more comfortable doing raw code in ASP then ASP.NET
Thank goodness for ASPRunner .NET...
Best

Mark, Big Timber, MT

admin 6/26/2018

Redirect is not a problem, you can redirect in server side event like AfterAdd. Opening a page in a new tab - that is more complicated.