Ahmed Ayman
Ahmed Ayman

Reputation: 51

How to go to an ad on button click in a new tab at first visit only in asp.net?

I am using propeller ads smart direct link to go to an ad on download button click.What I would like to achieve is to open the ad in new tab on first click and after making sure that the ad is opened and on second click open the download page in a new tab. I am using this code :

Response.Write("window.open ('link','_blank');");

which I got from the internet but it gets blocked by the browser so on second click the user can open the download link if he allowed popup for the download link.

Upvotes: 0

Views: 350

Answers (1)

Ahmed Ayman
Ahmed Ayman

Reputation: 51

OK I have found an answer to this. What I did :

  1. Added OnClientClick="document.forms[0].target ='_blank';" to the button which isn't blocked by ad blockers or Chrome.
  2. In the Server Side Code I added on page load !ispostback a Viewstate and made its value false so the code will be :

         if (!IsPostBack)
         {
             ViewState["isclicked"] = false;
         }
    
  3. On ServerSide Button clicked I checked if the viewstate is true or false If it is false go to ad and make the viewstate value false Else go to download page. Code:

        if ((bool)ViewState["isclicked"] == false)
        {
            ViewState["isclicked"] = true;
            Response.Redirect("ad direct link");
        }
        else
        {
            ViewState["isclicked"] = false;
            Response.Redirect("download link");
        }
    

Upvotes: 1

Related Questions