Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Query String

  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Query String

    Just curious. I have a website currently that has query strings to load individual pages, like this

    PHP Code:
    <?php
        $main 
    $_GET['page'];

        if(
    $main == 'history'){
            include_once(
    'history.php');
        } else if(
    $main == 'contact'){
                   include_once(
    'contact.php');
            } else{ include_once(
    'main.php');
    ?>
    How would I obtain the same simple functionality with ASP?

    Thanks

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I've not used ASP for years, but I guess it goes something like this
    Code:
    <%
    dim page
    If Request.QueryString<>"" Then
          If Request.QueryString("page")<>", " Then
               page=Request.QueryString("page")
               <!--#include file=""&page&".inc"-->
          end if
    end if
    I wasn't that far off I don't think, just did a search for you
    Code:
    <%
    Dim whichpage
    whichpage = Request.QueryString("page")
    If whichpage = "" Then
    whichpage = "default"
    %>
    <!-- #include file="<%= whichpage %>.asp" -->
    <%End If %>
    Last edited by Nightfire; 03-31-2007 at 02:58 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    I don't think you can use a variable in a page name like that. Unfortunately, Classic ASP requires you to hard code the include names - you can't build it from a variable like that.

  • #4
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,069
    Thanks
    4
    Thanked 8 Times in 8 Posts
    You can however include a different include file by putting the include file into the If/Then statement like so
    Code:
    <%
    Dim whichpage
    whichpage = Request.QueryString("page")
    If whichpage = "history" Then
    %>
         <!-- #include file="history.asp" -->
    <%ElseIf  whichpage="contact" Then %>
          <!-- #include file="contact.asp" -->
    <%Else%>
         <!-- #include file="main.asp" -->
    <%End If %>

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If these are file on the file system - as apposed to database records - then you can use server execute to load the files

    http://computer-helpforum.com/asp/as...te/default.asp


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •