How To: Redirect a user to a page using popups

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Source.aspx.cs" Inherits="Source" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
  <title>Untitled Page</title>
  <form id="form1" runat="server">
          <asp:HyperLink ID="hlRedirect1" runat="server" NavigateUrl="RedirectToSite.aspx?site=1">Redirect 1</asp:HyperLink><br />
          <asp:HyperLink ID="hlRedirect2" runat="server" NavigateUrl="RedirectToSite.aspx?site=2">Redirect 2</asp:HyperLink><br />
          <asp:HyperLink ID="hlRedirect3" runat="server" NavigateUrl="RedirectToSite.aspx">Redirect 3</asp:HyperLink>&nbsp;</div>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RedirectToSite.aspx.cs" Inherits="RedirectToSite" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head id="Head1" runat="server">
   <title>Redirect to site</title>
   <script type="text/javascript">
       function popup(mylink, windowname)
       if (! window.focus)return true;
       var href;
       if (typeof(mylink) == 'string')
          href=mylink.href;, windowname, 'width=800,height=600,scrollbars=yes');
       return false;
<body onload="<%= redirectionEvent %>" >
   <form id="form1" runat="server">
       <asp:Label ID="lblRedirectStatus" runat="server" Text="Unknown site..."></asp:Label></div>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class RedirectToSite : System.Web.UI.Page
    protected string redirectionEvent = "";
    protected void Page_Load(object sender, EventArgs e)
        //our popup call
        string redirectionInfo = "popup('@popurl', 'ad')";
        //the popup url
        string popurl = "";
        //check whether there is a value for our querystring
        if (Request.QueryString["site"] != null)
            //get the siteid
            string siteId = "";
            siteId = Request.QueryString["site"].ToString();

            //if siteid is one then...
            if (siteId == "1") { popurl = ""; }
            //if siteid is two then
            else if (siteId == "2") { popurl = ""; }

            //display our redirect information
            lblRedirectStatus.Text = "Redirecting to " + popurl;
            //replace the @popurl placeholder with the popurl value
            redirectionEvent = redirectionInfo.Replace("@popurl", popurl);

No comments:

Post a Comment