How do I repeat pages.....

J

Jane sharpe

Hi

I have an aspx page that is called with an ID parameter, it then performs a SQL statement using the ID field and displays some data on the page. It works a treat

What I want to do however, is to run it n number of times with different ID's - and have the results displayed in one page one after the other, e.g

if the user selects 4 ID's then the page will displa

Page for ID

Page for ID

Page for ID

Page for ID

Can anyone point me in the right direction to achieve this please

Jan
 
C

Cowboy \(Gregory A. Beamer\)

For a limited number of choices, you can simply add four panels and hide all
but the one with the info you wish to show. This is not the best solution
for flexibility, but it is a rather fast and easy one to implement.

For more scalability, you can create four user controls and dynamically load
the one that fits the ID. This allows you to add extra choices without
having to recode the page or change the architecture. Another option is to
create four pages and Server.Transfer the person to the correct page. With
Server.Transfer, the user will still see the URL:

http://mysite.com/choicePage.aspx?ID=1

instead of

http://mysite.com/page1.aspx

In many respects, this is more maintainable, as you can have a designer
change the pages, including content elements, with his/her favorite HTML
editor (FrontPage, Dreamweaver).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
Jane sharpe said:
Hi,

I have an aspx page that is called with an ID parameter, it then performs
a SQL statement using the ID field and displays some data on the page. It
works a treat.
What I want to do however, is to run it n number of times with different
ID's - and have the results displayed in one page one after the other, e.g -
 
J

Jane sharpe

Thanks Gregory,

I think I understand what you're saying (sorry, I'm still learning) - th enumber of pages to join is variable from 1 to n, does this effect your answer at all ?

Jane
 
C

Cowboy \(Gregory A. Beamer\)

With 1 to n, I would not use panels (first suggestion). The controls or
pages with Server.Transfer both apply. The decision of which to do is
largely based on who maintains content items. If you have a graphic designer
maintaining the content, I would go with pages, as controls require the
person to either use notepad or have a copy of a .NET editor (Visual Studio
..NET, SharpDevelop, et al).

The basic tree goes like this, with pages:
----------------------------------------

Assuming URL format of
http://mysite.com/pageLoader.aspx?ID=1

pageLoader.aspx - page that gets ID
page1.aspx
page2.aspx
page3.aspx
page4.aspx

In pageLoader.aspx:

VB.NET
Dim id As String = Request("ID").ToString()
Server.Transfer("page" & id & ".aspx")

C#
string id = Request("ID").ToString();
Server.Transfer("page" + id + ".aspx");


Controls
---------
Controls gets a bit more complex (and more difficult to maintain for graphic
designers/HTML artists).

pageLoader.aspx - for consistency
page1.ascx
page2.ascx
page3.ascx
page4.ascx

In pageLoader.aspx you will drag a panel on the page in design view. I will
use Panel1, as that is the default, but you would probably want to be more
descriptive. In the CodeBehind (.vb or .cs file), you will use a statement
like this:

VB.NET
Dim id As Integer = Convert.ToInt32(Request("ID"))
Select Case id
Case 1
Panel1.Controls.Add(page1)
Case 2
Panel1.Controls.Add(page2)
Case 3
Panel1.Controls.Add(page3)
End Select

C#
int id = Convert.ToInt32(Request("ID"));
switch(id)
{
case 1:
Panel1.Controls.Add(page1);
break;
case 2:
Panel1.Controls.Add(page2);
break;
case 3:
Panel1.Controls.Add(page3);
break;
}

In this example, you can name the added controls anything you want, so

Panel1.Controls.Add(Administrators)
Panel1.Controls.Add(Users)

You would then make controls Administrators.ascx and Users.ascx.

NOTE: You can also apply this type of logic to example1 (with pages), if you
wish to have the pages by role (Administrators, Users, ReportUsers, et al)
instead of numbers (page1, page2, page3).

Back to pages
--------------

Assuming the following pages

pageLoader.aspx
Admin.aspx
User.aspx
ReportUser.aspx

VB.NET
Dim id As Integer = Convert.ToInt32(Request("ID"))
Select Case id
Case 1
Server.Transfer("Admin.aspx")
Case 2
Server.Transfer("User.aspx")
Case 3
Server.Transfer("ReportUser.aspx")
End Select

C#
int id = Convert.ToInt32(Request("ID"));
switch(id)
{
case 1:
Server.Transfer("Admin.aspx");
break;
case 2:
Server.Transfer("User.aspx");
break;
case 3:
Server.Transfer("ReportUser.aspx");
break;
}
Okay, you are probably at information overload right now. I would suggest
trying the page version first, as it is the easiest to design for. You can
either use the simplified version (page1.aspx, et al) or the role version
(Admin.aspx). I would suggest matching ID to page#.aspx, as it is easier.
You can move over to the role based version, if it makes more sense, after
you have things working.

For your own experience, experiment with the controls version at some time,
as you might find it better suited for your app(s) in the long run.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
Jane sharpe said:
Thanks Gregory,

I think I understand what you're saying (sorry, I'm still learning) - th
enumber of pages to join is variable from 1 to n, does this effect your
answer at all ?
 
G

George Ter-Saakov

I would create UserControl which creates output of one page.
And then i would add it to the page itself as many time as i need.

George.

Jane sharpe said:
Hi,

I have an aspx page that is called with an ID parameter, it then performs
a SQL statement using the ID field and displays some data on the page. It
works a treat.
What I want to do however, is to run it n number of times with different
ID's - and have the results displayed in one page one after the other, e.g -
 
J

Jane sharpe

Hmmmm, I've had a go at the suggestions Gregory, I think I understand them but I dont think they do what I need.... I'll explain a bit more....

Imagine I have Pageload.aspx, which currently calls ShowName.aspx for a particlar Id on a buttonClick event... so at the moment in my buttonclick I have ....

Response.Redirect("ShowName.aspx?Id=1")

Which takes me to a ShowName.aspx and correctly shows me "John Smith"

Now I want to upgrade this, so that a user can select multiple Id's, and they all get shown on 1 page after the buttonclick event, so if a user selects Id's 1,3 and 5 (could be n number) I loop around the Id's each time building some "temporary page" which I can then view with a Response.Redirect or something similar, which will show

John Smith
Jane Green
Bob White

Being Id's 1, 3 5 respectively. I'm sorry If I've misunderstood you, but I couldnt make your suggestions behave in this way.... thanks, Jane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top