View Full Version : calling a page inside a page
Crash1hd
05-02-2003, 07:25 AM
Is there a way to call a page like so in a link
<% Sub LostPassorUser() ''''''''''''''''' %>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head><title>Title</title>
</head>
<body>
<P Class=text>data goes here</p>
</body>
</html>
<% End Sub ''''''''''''''''''''''''''''''''''''''' %>
P.S. there would be more then just one sub in the same asp file
in a link like so
<a href="<% Sub LostPassorUser() ''''''''''''''''' %>">click here</a>
Roy Sinclair
05-02-2003, 03:16 PM
No, you are essentially wanting a client side action (clicking a link) to control a server side script. The problem is that the server side script has already completed running by the time the user can interface with the page.
ecnarongi
05-02-2003, 10:13 PM
you could have a link that submits a form on your page that executes the asp page. just reference the form when the link is clicked and send whatever information to that form, and that form will send the information to the asp page.
I hope that helps
Crash1hd
05-19-2003, 11:17 AM
why does the following not work for me
<a href="Admin.asp?dbshow=OK">testing link here</a>
is the link you click in Admin.asp
then I have
If dbshow <> "" Then
Call DisplayDBForm()
Else
Call DisplaySubmitForm()
End If
both having valed subs yet all that ever shows up is DisplaySubmitForm() if I change the <> "" to = "" then the DisplayDBForm() shows up the link shows
http://site.com/Admin.asp?dbshow=OK
What could I be doing wrong
P.S. the following variables are called
Select Case Request.ServerVariables("REQUEST_METHOD")
Case "Get"
dbshow = Request.QueryString("dbshow")
End Select
??????????????????????????????????????????????
Hmm. Would be easier if we could see the whole code + i don't quite understand the explanation. Anyway, i usually check for the length of the value. Like
If Len(Request.QueryString("dbshow")) > 0 Then
Call DisplayDBForm()
Else
Call DisplaySubmitForm()
End If
So if there's nothing in the querystring, the DisplaySubmitForm() is called, else, the DisplayDBForm() is called.
<edit>
I think i might know why it doesn't work (i'm relying on my psychic powers here since i don't know your code, so i could be off); you check for the method, but did you post a form in this page to itself, and with the 'get' method?
It's not because you have a value in the querystring, that you've used the get method. In fact, i somethimes add a querystring to the action in the formtag, but use the post-method. (if i post to a page that can also be called from other pages) Or i add some variabels to the querystring but i display a link (like i suppose you did --> impression i get from your post). If you hit the link, a page is requested, but there is no form posted so the get-method was not used and dbshow will be empty
</edit>
whammy
05-19-2003, 07:31 PM
What I usually do in this case is use a tricky pixel or something... check this out:
function trackThis(btn,img,args) {
/*
* This function changes the appropriate image to
* execute a page, which then returns an image
*/
if(btn.value == "Yes")
{
document.images[img].src = 'somepage.asp?I=1&' + args;
}
else
{
document.images[img].src = 'somepage.asp?I=0&' + args;
}
btn.disabled = true;
}
Basically all I'm doing there is changing a blank .gif (transparent) to the processing page using javascript, and passing parameters like that as well... as long as javascript is enabled, it works just fine - you can even write the button out with javascript, etc. if you want to go that route.
What's really cool about this, is you can have your target page redirect to an image once it's done processing - for instance "Thank You" or whatnot...
Crash1hd
05-19-2003, 10:38 PM
Thankyou to both of you Raf and Whammy you have both been very helpful but what raf had indicated works perfectly!
If Len(Request.QueryString("dbshow")) > 0 Then
but why is it that
If Len(Request.QueryString("dbshow")) = 1 Then
doesnt work I was hoping to do multiple choices
whammy
05-20-2003, 01:20 AM
Try that tricky pixel thing sometime, it's fun. ;)
Crash1hd
05-20-2003, 04:44 AM
Whammy I will check it out just cause lol :)
I figured out what to use that would solve my problem lol
You said to use
If Len(Request.QueryString("dbshow")) > 0 Then
and that worked fine but I wanted the link to be specific so that it would be something like
If Len(Request.QueryString("dbshow")) = 1 Then
yet for some odd reason it didnt like that (nothing new) so I went back to some research and found that
If CInt(Request.QueryString("dbshow")) = 1 Then
works great and I am able to use more the one choice on the same page so my new question is....
What does CInt and Len stand for and what are the differences??
Is there a way of making this work the same without it showing up in the QueryString say POST instead of GET??
Also How can I make the following code work as a one liner
<% If submitnumber > 1 AND username = "" Then
Response.Write("<span style=""color:#cc0000"">")
ElseIf usernametaken = True Then
Response.Write("<span style=""color:#cc0000""> * ")
End If %>
For Example
<% If submitnumber > 1 AND username = "" Then Response.Write("<span style=""color:#cc0000"">") ElseIf usernametaken = True Then Response.Write("<span style=""color:#cc0000""> * ") End If %>
Gives me this error
Microsoft VBScript compilation error '800a03f6'
Expected 'End'
/login/admin.asp, line 186
ElseIf usernametaken = True Then
OK. Let's start with the Len and CInt
If you use the Len() function (like Len(variable)), then the length of the variabels value is returned. Meaning, if the variable doesn't have a value, because it is emty or the variable is not in the collection (in your case, is not in the querystring), then the length of the value will be 0. So in
If Len(Request.QueryString("dbshow")) > 0 Then
it will be 0 if the page is loaded the first time (since dbshow will not be in the querystringà but will be 2 after hitting the link that appends 'dbshow=OK' to the querystring.
Now. If you'de like to run some code, depending on the value of dbshow, then you first check to see if it is empty, and if not, then check on the value. Like
If Len(Request.QueryString("dbshow")) > 0 Then
some code
else
if Request.QueryString("dbshow") = "OK" then
some other code
else
if Request.QueryString("dbshow") = "NOK" then
some other code
else
' if it is none of the expected values
response.write("Your trying to hack into my app by changing the querysring. I'll now hunt you down.")
end if
end if
end if
(If you have more then 3 possibilitys, use the select-case form)
Notice the quotes around the querystringvalues! All values in the querystring or that or in a posted form, are strings! Even if they are numeric!! So 'if Request.QueryString("dbshow") = 1' would not work, buth 'Request.QueryString("dbshow") = "1" ' would.
CInt --> converts the value into an integer. So converts string "1" into number 1 (see difference above) or 1.4564356 into 1
Is there a way of making this work the same without it showing up in the QueryString say POST instead of GET??
Sure. You can store the value in a hidden formfield, and run the same code in your asp. Just need to replace request.querystring by request.form
Also How can I make the following code work as a one liner
Why a single line form? It's not easier to read or code or whatever.
And you can't us it with elseif (as far as i know)
Actually, elseif (-> = the block form syntax) doesn't work like that. You need multiple elseif's and an else clause for when none of the elseif's is true.
So you'd probably need
<%
If submitnumber > 1 then
if username = "" Then
Response.Write("<span style=""color:#cc0000"">")
end if
if usernametaken = True Then
Response.Write("<span style=""color:#cc0000""> * ")
end if
else
some code if submitnumber if 1 or lower
End If %>
or something like that
Whammy,
Gotta try that someday.
Crash1hd
05-20-2003, 08:31 AM
WOW Thankyou for all that info lol ok now I have the following code I was wondering how I could shorten the End If's as if I want to add more choices I have to add more End Ifs and well that fills up a lot of space
'************************************ MAIN PROGRAM
If CInt(Request.QueryString("dbshow")) = 1 Then
Call DisplaySubmitForm()
Call DisplayDBForm1()
Else
If CInt(Request.QueryString("dbshow")) = 2 Then
Call DisplaySubmitForm()
Call DisplayDBForm2()
Else
If CInt(Request.QueryString("dbshow")) = 3 Then
Call DisplaySubmitForm()
Call DisplayDBForm3()
Else
IF CInt(Request.QueryString("method")) = 2 Then
Call EditMember()
Call DisplaySubmitForm()
Call DisplayDBForm1()
Else
IF CInt(Request.QueryString("method")) = 3 Then
Call DeleteMember()
Call DisplaySubmitForm()
Call DisplayDBForm1()
Else
If First_Name <> "" AND _
Last_Name <> "" AND _
Address <> "" AND _
City <> "" AND _
Province <> "" AND _
PostalCode <> "" AND _
D_Phone_A <> "" AND _
D_Phone_B <> "" AND _
D_Phone_C <> "" AND _
username <> "" AND _
pass <> "" AND _
ValidEmail(email) = True Then
Call CheckForDupes()
If usernametaken = False AND emailaddresstaken = False Then
If Len(Request.QueryString("method")) = 1 Then
Call InsertNewMember()
Call DisplaySubmitForm()
Call DisplayDBForm1()
Else
Call DisplaySubmitForm()
Call DisplayDBForm1()
End If
Else
Call DisplaySubmitForm()
Call DisplayDBForm1()
End If
Else
Call DisplaySubmitForm()
Call DisplayDBForm1()
End If
End If
End If
End If
End If
End If
Best start a new thread for new questions, since a lott of people just read the new threads + it keeps the searchresult purer and cuts down on scrolling
About the code.
Hard to cut that down, since i don't know your applications logic, but here are some tips:
- use the select case control of flow
- try to not repeat code
Something like (layout messed up by this forum)
Select Case CInt(Request.QueryString("dbshow"))
Case 1
_____Call DisplaySubmitForm()
Call DisplayDBForm1()
Case 2
Call DisplaySubmitForm()
Call DisplayDBForm2()
Case 3
Call DisplaySubmitForm()
Call DisplayDBForm3()
__Case Else
_____ Select Case CInt(Request.QueryString("method"))
Case 1
If First_Name <> "" AND Last_Name <> "" AND Address <> "" AND City <> "" AND Province <> "" AND PostalCode <> "" AND _
D_Phone_A <> "" AND D_Phone_B <> "" AND D_Phone_C <> "" AND username <> "" AND pass <> "" AND ValidEmail(email) = True Then
Call CheckForDupes()
If usernametaken = False AND emailaddresstaken = False Then
Call InsertNewMember()
end if
end if
Case 2
Call EditMember()
Case 3
Call DeleteMember()
Case Else
response.write("Beep ! Error. Invalid values received")
End select
Call DisplaySubmitForm()
Call DisplayDBForm1()
End Select
It's easy to expand and displays the logic more clearly --> easier to debug.
Crash1hd
05-20-2003, 11:56 PM
Ok I have a silly question but I think thats it for this page lol how did you get the code to show up properly I mean with the tabs everytime I do it all the tabs get removed??
Well, first of all, i use the \[code\] tags instead of the \[quote\] tags :D (without the slashes of course) and then i use spaces in stead of tabs. But even then, you get this weird underscores etc. I think it's displayed better if you use \[PHP\] tags but be sure to indicate then that you're using ASP or VBscript.
Crash1hd
05-21-2003, 07:38 AM
Ok Cool!
I didnt realize that # was ment for code
I am learning new things all the time
I think tab works great as long as you write
it in Notepad first and then copy and paste it!
Thanks again for all the help
whammy
05-24-2003, 01:10 AM
Ok... I'm gonna close this thread now (just post any further questions in another), since it's apparently outlived its usefulness. ;)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.