Click to See Complete Forum and Search --> : ASP.NET and SSI
kwilliams
03-14-2006, 12:36 PM
This is what I'm trying to setup:
page1.aspx
<%
'Declare main form variable
Dim page_id As String = "login" 'Static test variable
'Dim page_id As String = trim(Request.Form("page_id")) 'Dynamic variable to be used
%>
<%
'***LOGIN PAGE***
If page_id = "login" Then
%>
<!--#include virtual="login.aspx" -->
<%
End If
%>
page2.aspx
<%
'Declare variables
'Dim page_title As String
Dim page_description As String
Dim page_content As String
'Response.Write("test") 'TEST
'Page title
Dim page_title As String = "Login Page"
'Page description
page_description = "This is the login page."
'Page content
page_content = "This the content for the login page."
%>
page3.aspx
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" aspcompat="true" Debug="true" %>
<%
<%
Response.Write("<title>" + page_title + "</title>")
%>
Resulting Error
Compilation Error
Compiler Error Message: BC30451: Name 'page_title' is not declared.
...and when I add <% Response.Write("test") %> to page2.aspx, and comment out the <% Response.Write("<title>" + page_title + "</title>") %>, I don't receive that error and the "test" does get written out. So I know that the page setup is working. I'm just not sure why the last display page (page3.aspx) is not seeing the variable from the SSI.
I'm using this setup so that I can have one SSI that contains other SSI's that actually contain each page's data. I'll then pull each of the page's data using <%Dim page_id As String = trim(Request.Form("page_id"))%> on page1.aspx.
If anyone could let me know what I'm doing wrong, it would be great. Thanks.
sirpelidor
03-14-2006, 01:47 PM
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" aspcompat="true" Debug="true" %>
<%
<%
Response.Write("<title>" + page_title + "</title>")
%>
Compiler Error Message: BC30451: Name 'page_title' is not declared.
if you declare the language as VB, it should be:
Response.Write("<title>" & page_title & "</title>")
+ is being use by C#
kwilliams
03-14-2006, 02:07 PM
I've used both + and & in VB with no problems before, although I know of certain instances when dealing with multi-line code that I've needed to use & instead of +.
But I still tried replacing the + with &, and still received the exact same error "Name 'page_title' is not declared.". I also tried just having Response.Write(page_title), but no luck. If you have any other suggestions, that would be great. Thanks.
sirpelidor
03-14-2006, 03:09 PM
<%
<%
Response.Write("<title>" + page_title + "</title>")
%>
Resulting Error
Compilation Error
could that be a extra <% ?
hahah tak got it for ya, i didn't even noticed u declare page_title at page2.aspx, cool!
takkie
03-14-2006, 03:11 PM
1. Either + or & are fine for concatenation, just becareful if you are doing this, response.write(strA + strB) where strA is 3, strB is 8.... that will display 11 instead of 38...
2. page3.aspx have no idea what the page_title is, how can it be displayed?? page_title is only visible within page2.aspx... page3.aspx cannot see it. Thus returning a not declared error. You can either put it in session, by doing this, session("pageTitle") = page_title in your page2.aspx.... and then age page3.aspx, do this, response.write(session("pageTitle"))....then it will work..
-tak
kwilliams
03-14-2006, 03:13 PM
No. That was just a mistake on my post...unfortunately. That would be nice if it was that simple. I've been messing around with it some more, and I think that it has to do with the conditional statements used. If I just place default variables on the page outside of any conditional statement, then they show up properly. I've tried using If...Else, Case, and Conditional SSI, but none of them work. I just don't know what to do, because it seems like my method is pretty straight forward.
takkie
03-14-2006, 03:20 PM
based on what we can see in your code snippet, what does it have to do with the conditional stuff? page2 and page3 doesnt check for anything...and page1 doesnt set anything... ??
unless thats not complete, or not uptodate.. why dont you copy and paste the latest one that you have?
tak
takkie
03-14-2006, 03:21 PM
by the way... why are you doing it in such an asp way??
kwilliams
03-14-2006, 03:44 PM
1. Either + or & are fine for concatenation, just becareful if you are doing this, response.write(strA + strB) where strA is 3, strB is 8.... that will display 11 instead of 38...
Thanks for the heads-up on that one. Now I remember where I had that problem. I'll just have to get in the habit of using & instead o + so that I won't run into issues with calculations.
2. page3.aspx have no idea what the page_title is, how can it be displayed?? page_title is only visible within page2.aspx... page3.aspx cannot see it. Thus returning a not declared error. You can either put it in session, by doing this, session("pageTitle") = page_title in your page2.aspx.... and then age page3.aspx, do this, response.write(session("pageTitle"))....then it will work..
I forgot to add that page3.aspx includes an SSI, like this:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" aspcompat="true" Debug="true" %>
<!--#include virtual="bgscripts/aspx/page2.aspx" -->
Response.Write("<title>" + page_title + "</title>")
...so that's where the variable gets pulled from (sorry about that). I know that the way I explained it is kind of confusing, but I tried to keep it as simple as I could. Instead of using page1, page2...I'll use the name of what they do: mainssi.aspx, subssi.aspx, and display.aspx. There are 2 variables being passed, and they are: page_id and page_title.
mainssi.aspx - Pulls a form variable (page_id), and displays the proper SSI for that case, like this:
<%
Dim page_id As String = "login"
Session("page_id") = page_id
Select Case Session("page_id")
Case "login"
<!--#include virtual="bgscripts/aspx/login.aspx" -->
Case "home"
%>
<!--#include virtual="bgscripts/aspx/home.aspx" -->
<%
Case else
<!--#include virtual="bgscripts/aspx/default.aspx" -->
End Select
%>
subssi.aspx - Declares the page_title variable, and assigns values to that variable, like this:
<%
Dim page_title As String = "Login Page"
%>
display.aspx - Pulls the mainssi.aspx SSI, and calls the "page_title" variable from the subssi.aspx SSI through the mainssi.aspx SSI, like this:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" aspcompat="true" Debug="true" %>
<%
<!--#include virtual="bgscripts/aspx/mainssi.aspx" -->
<%
Response.Write("<title>" + page_title + "</title>")
%>
It's set up as a nested SSI. The reason that I set it up this way is that so each page for the site can have it's own SSI file that contains the page variables, so that from the main ASP.NET display page, I can just call one variable name (page_title).
As I stated in a previous post, this method does work properly, as I was able to Response.Write("test") with no problem. I was also able to call the "page_title" variable if it was outside of a conditional statement, so I think that the problem lies there. If you or anyone has any more suggestions, they would be greatly appreciated. Thanks.
takkie
03-14-2006, 03:52 PM
1. out of curiousity, why are you doing so many includes? instead of just load a usercontrol (ascx)?
And how is subssi.aspx being called? (did you leave it out in mainssi.aspx?), i dont see it being called from mainssi.aspx...
??
sirpelidor
03-14-2006, 03:56 PM
It's set up as a nested SSI. The reason that I set it up this way is that so each page for the site can have it's own SSI file that contains the page variables, so that from the main ASP.NET display page, I can just call one variable name (page_title).
sorry, i don't mean to drift you off the subject. I meant to ask the same question like Tak did before my first post. But I didn't because I saw you have a background of doing XML and CSS and a brunch of web stuff. I thought maybe you have your own little unique way to rend your XML document.
Now that I see your reason, may I suggest you store all those variables into a object, and pass that object around through a session variable? I think you will find that a lot easier.
kwilliams
03-14-2006, 04:00 PM
I'm not actually using that many includes within one page. When the pages get processed by the server, they're only seeing two SSI's depending on the page_id value. The main SSI displays the sub SSI's depending on the page_id value. And I've never used a usercontrol, so I wouldn't have any idea of how to do so.
The subssi.aspx file is being called from the mainssi.aspx page, like this:
<%
Dim page_id As String = "subssi"
Session("page_id") = page_id
Select Case Session("page_id")
Case "subssi"
<!--#include virtual="bgscripts/aspx/subssi.aspx" -->
<%
Case else
<!--#include virtual="bgscripts/aspx/defaultssi.aspx" -->
End Select
%>
I had just forgot to change the "login", "home", etc... on the mainssi.aspx page between what I'm actually using vs. what I'm posting (for security reasons).
kwilliams
03-14-2006, 04:11 PM
Hi sirpelidor,
Thanks for the break:) Ok, I changed the mainssi.aspx page to read:
<%
'Session("page_id") = trim(Request.Form("page_id")) 'actual var
Session("page_id") = "login" 'test var
Select Case Session("page_id")
Case "login"
Session("page_title") = "Login Page"
Case "home"
Session("page_title") = "Home Page"
End Select
%>
...and it worked. I had tried this earlier, but had thought the error had to do with that variable. It had to do with another variable being pulled from that page. Once I set them as Sessions on the display.aspx page, like this:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" aspcompat="true" Debug="true" %>
<!--#include virtual="bgscripts/aspx/mainssi.aspx" -->
<%
Response.Write("<title>" + Session("page_title") + "</title>")
...everything worked great. Thanks for helping to clear my head, and I hope that you and everyone else has a great afternoon.
takkie
03-14-2006, 04:21 PM
oh ok...
good luck..
kwilliams
03-14-2006, 04:51 PM
I think your setup is very weird... (no offense), it took a while for it to sink in to my head...
so, display.aspx calls mainssi.aspx, depending on what it is, mainssi.aspx will call xxx.aspx, subssi.aspx, or whatever.aspx...
I understand that it can be "weird" to some, but I'm creating a site that's completely dynamic and pulls from source files as opposed to static scripts.
I am not an asp guy (i am more of a java, c++, and .net guy), but i do know that the classic asp includes different files, and it 'inherits' all the variables within that include files... I dont konw if yoursetup will work that way or not, but i can thnk of a few things..
1. the way how the engine renders the pages are different. You are trying to do the response.write(page_title), before subssi.aspx was actually binded to the mainssi, or display.aspx.
2. The fact that you can do, response.write("test"), only means that the files were loaded, that doesnt mean that you were able to load the variables that you wanted..
I wasn't just doing a Response.Write("test"). I was also calling the variable from the display page just fine as long as the variable was outside of a conditional statement. But when I placed that same variable within any type of conditional statement, it would give me that error.
Like what sirpelidor suggested.... make your "mainpage" ( I dont know which one is your main base page) contain a variable called, pageID.... and then within your other aspx (mainssi or subssi)... do this..
CType(Me.Page, TheClassForDisplayAspx).pageID = WhatEverPageIDItIs
And then at Display.aspx, do response.write(me.pageID)
see if that works..
-tak
Thanks for the suggestion, but I'll go ahead and stick with what I have. Thanks again for all your help...I appreciate it:)