Search

Atalasoft Knowledge Base

HOWTO: Make Sure Two Tabs With the Same .ASPX Page Don't Interact With Each Other

Administrator
DotImage

Legacy Controls NOTICE

This article references our legacy Web Forms Web Viewing controls (WebImageViewer, WebAnnotationViewer, WebThumbnailViewer). It is preserved for archival purposes, but support strongly recommends using our modern HTML5 web controls: WebDocumentViewer, WebDocumentThumbnailer instead)

INFO: WebDocumentViewer Whitepaper - Getting Started With Web Viewing

Main Article Content

If you load the same page in two tabs in your browser, the browser will send the same cookies to both pages and then both pages will share a session ID.

Since our controls use the session ID to create filenames in the cache, this can result in the two tabs conflicting with each other.

To solve this, add the following code to your page (you need to update with our web control IDs)

protected override void OnPreInit(EventArgs e) 
{ 
   // this comes in on AJAX requests and tile and thumb requests, you must use it if it exists 
   string id = Request.QueryString["atala_id"]; 
   // these are put in a hidden variable and is for post-backs 
   string ivid = Request.Params["postback_ivid"]; 
   string tvid = Request.Params["postback_tvid"]; 
   // if it's the first request or a Post-Back 
   if (id == null) 
   { 
      string newGuid = Guid.NewGuid().ToString().Replace('-', '_');
      if (ivid != null) 
      { 
         // it was a post-back, use the old id 
         WebImageViewer1.ID = ivid; 
      } 
      else if (!WebImageViewer1.ID.StartsWith("gen_")) 
      { 
         // it's the first page request, generate an ID 
         WebImageViewer1.ID = "gen_iv_" + newGuid; 
      } 
      if (tvid != null) 
      { 
      // it was a post-back, use the old id 
      WebThumbnailViewer1.ID = tvid; 
   } 
   else if (!WebThumbnailViewer1.ID.StartsWith("gen_")) 
   { 
      // it's the first page request, generate an ID 
      WebThumbnailViewer1.ID = "gen_tv_" + newGuid; 
   } 
   // This makes sure that you can still use JavaScript with the ID names that you know
   ClientScript.RegisterClientScriptBlock(typeof(_Default), "MakeObjects", "var WebImageViewer1; var WebThumbnailViewer1;" + 
      "function MakeObjects()\n" + 
      "{\n" + 
      "\tWebImageViewer1 = " + WebImageViewer1.ClientID + ";\n" + 
      "\tWebThumbnailViewer1 = " + WebThumbnailViewer1.ClientID + ";\n" + 
      "}\n", true); 
   ClientScript.RegisterStartupScript(typeof(_Default), "CallMakeObjects", "atalaInitClientScript('MakeObjects();')", true); 
   } 

   else
   {
      // it's an AJAX request or a Tile or Thumb request -- figure out which control they want
      // by looking at the ID value
      if (id.StartsWith("gen_iv_"))
      {
         WebImageViewer1.ID = Request.QueryString["atala_id"];
         WebThumbnailViewer1.ID = WebImageViewer1.ClientID.Replace("gen_iv_", "gen_tv_");
         WebThumbnailViewer1.ViewerID = WebImageViewer1.ClientID;
      }
      else if (id.StartsWith("gen_tv_"))
      {
         WebThumbnailViewer1.ID = Request.QueryString["atala_id"];
         WebImageViewer1.ID = WebThumbnailViewer1.ClientID.Replace("gen_tv_", "gen_iv_");
         WebThumbnailViewer1.ViewerID = WebImageViewer1.ClientID;
      }
   }

   base.OnPreInit(e); 
}

And you need to add the following to your ASPX page for postbacks to work

<input type="hidden" name="postback_ivid" value="<%=WebImageViewer1.ClientID %>" /> 
<input type="hidden" name="postback_tvid" value="<%=WebThumbnailViewer1.ClientID %>" />

Original Article:
Q10227 - HOWTO: How to make sure two tabs with the same .ASPX page don't interact with each other

Details
Last Modified: 6 Years Ago
Last Modified By: Administrator
Type: HOWTO
Article not rated yet.
Article has been viewed 389 times.
Options
Also In This Category