0

on button click i have opened 5 different pages on different window.

int i = 1;
do
{
    Session["ii"] = i;                 
    string redirect = "<script>window.open('Printscreen.aspx');</script>";
    Response.Write(redirect);
    i++;
}                
while (i <= 5);

on every page load i want to generate an unique number. fro 5 pages the number should be 1 2 3 4 5 resp. using random give duplicate values... plz help

Rohit Prakash
  • 1,975
  • 1
  • 14
  • 24
Jagrit Ojha
  • 167
  • 1
  • 2
  • 11
  • you'll either need to pass the pages their numbers, or have a global (static) variable that is updated when you get one, and have each page ask for it's number ... – Noctis Feb 23 '15 at 04:59
  • can you give me some coding on how to do that – Jagrit Ojha Feb 23 '15 at 05:05
  • see @Tamir answer for the first half, and his link is kind of what i'm suggesting in the second half. – Noctis Feb 23 '15 at 08:40

2 Answers2

0

About the random duplicate values, the following answer will explain how to get unique random number: https://stackoverflow.com/a/768001/94334

Anyhow, you can add query string parameter to the pages you're referring to so they will read and display the values from the url QS parameter.

Community
  • 1
  • 1
Tamir
  • 3,833
  • 3
  • 32
  • 41
0

I wouldn't think a session-variable is the correct way to go. The value of the session-variable would be "5", for every page, since session-variables are shared between the windows.

I think the best solution for you is something like the following:

var rand = new Random();
var i = 1;
do
{
    Response.Write("<script>window.open('Printscreen.aspx?ii=" + rand.Next(1, 101).ToString() + "');</script>");
} while (++i <= 5);

And then on the pages you get the querystring-variable either from javascript or with C#. With C# it's done like the following:

var myValue = Request.QueryString["ii"];
Sasse
  • 1,108
  • 10
  • 14
  • doing that gives problem Insufficient memory to continue the execution of the program. – Jagrit Ojha Feb 23 '15 at 09:55
  • I missed to increment the i variable, I've updated my answer with "while (++i <= 5);" Try again. – Sasse Feb 23 '15 at 10:02
  • Then I would believe you're doing something wrong. Show me your current code. The important part is to not create the "Random" object multilple time, so the object needs to be created outside of the loop. – Sasse Feb 23 '15 at 10:37
  • found the solution. instead of random if you just use i it gives. Thanx for d help – Jagrit Ojha Feb 23 '15 at 10:42