Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional 'include' files - Can I do it? 3

Status
Not open for further replies.

LEICJDN1

Technical User
Nov 27, 2002
201
GB
Hi all.

I have an ASP page, and wish to modify the appearance of a table depending on a variable.

Both tables are quite different in layout, so I though the easiest way would be to have two different include files, one for each table. Then, after I call the variable from the database, I could choose to inlcude the relevant file.

But can that be done? I know the include has to be in the html part and not enclosed in ASP tags.

Basically how can I do this:

If type="1" then include table1 else include table2

(not code, just the principle)

I could populate each cell of the table with ASP code to display one thing if type 1 and another if type 2 but that will be cumbersome to maintain, so I thought having two different tables would be a neat solution.

If I cannot do it with includes, how can I have two different tables and choose which one to display?

Thanks.
 
O' ya I did this also
off the code above

_____________________________________________________________________
onpnt2.gif

 
Why not use Server.Transfer and no more losing post data to one file or another.

<%
select case iVar
case 1
exFile = &quot;/inc/file1.asp&quot;
case 2
exFile = &quot;/inc/file2.asp&quot;
end select

Server.Transfer (exFile)
%>

Now you should be able to use Request also for each page you transfer, not to mention sending the data with Session's objects.


________
George, M
 
but with server.transer your control is lost on the main page, isn't it? with the execute you can conditionally keep control (to the user) without blinking to the server
(blinking to the server: send a blank screen while transfer accurs and sends back to parent page)

_____________________________________________________________________
onpnt2.gif

 
Just tested and nothing hapened.
I have
index.asp
<%
Server.Transfer &quot;index1.asp&quot;
%>

and index1.asp
<%
Response.Write &quot;OK&quot;
%>

And still see index.asp on my browser.

and here it's the microsoft help about it.
Code:
Remarks

When you call Server.Transfer, the state information for all the built-in objects will be included in the transfer. This means that any variables or objects that have been assigned a value in session or application scope will be maintained. In addition, all of the current contents for the request collections will be available to the .asp file receiving the transfer.

If the path you specify in the input parameter is for an .asp file in another application, the .asp file will execute as if it were in the application that contains the Server.Transfer command. In other words, all variables and objects that have been given application scope either by other .asp files in the application or by the application's Global.asa file will be available to the called .asp file. However, the path parameter must not contain an query string or ASP returns an error.

Server.Transfer acts as an efficient replacement for Response.Redirect. Response.Redirect tells the browser to request a different page. Since a redirect forces a new page request, the browser has to make two round trips to the Web server, and the Web server has to handle an extra request. IIS 5.0 introduced a new function, Server.Transfer, which transfers execution to a different ASP page on the server. This avoids the extra round trip, resulting in better overall system performance, as well as a better user experience.

So i think it's ok.(tested)

________
George, M
 
Here it's the confirmation that i'm right

... If the path you specify in the input parameter is for an .asp file in another application, the .asp file will execute as if it were in the application that contains the Server.Transfer command....


________
George, M
 
shaddow I never questioned you being right. after trying it I see this is very valid and I think it is going to change a few things and methods I use. I yet see another reason other members often post on this option in ASP. Wish I had more time lately to keep up with you people [sad].



_____________________________________________________________________
onpnt2.gif

 
I just argumenting my point, also as you see it was only with IIS5, since i always worked on IIS5 i dont knw the problem you've mentioned.

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top