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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hello username and includes

Status
Not open for further replies.

frogggg

Programmer
Jan 17, 2002
182
US
I'm trying to put a login box on the top of each page and hello username if the user logged on already, i.e. if they have a session variable. Maybe this is crazy, but I wanted to include it in each page just above my menu, so I don't have to put it on every page and for ease of changes.
Here's my code so far - it doesn't work, can someone help get me on the right track?

<%
if session(&quot;CandID&quot;) <> &quot;&quot; then
Response.Write &quot;Hello &quot; & session(&quot;CandID&quot;) & &quot;!&quot;
Response.Write &quot;If you are not &quot; & session(&quot;CandID&quot;) & &quot;please &quot;
Response.Write &quot;<a href='default.shtml'>log in.</a>&quot;

end if
%>

<form action=&quot;validatePassword.asp&quot; method=&quot;get&quot; name=&quot;frmLogin&quot;>

<h3>Already a member? <br>Login now.</h3>

<table>
<tr>
<td>Username: </td></tr>
<tr>
<td><input id=&quot;text1&quot; name=&quot;txtUserName&quot;></td></tr>
<tr>
<td>Password: </td></tr>
<tr>
<td><input type=&quot;password&quot; id=&quot;password1&quot; name=&quot;txtPassword&quot;></td></tr>
</table><br>
<input type=&quot;image&quot; src=&quot;images/img_Submit.gif&quot; value=&quot;Submit&quot; id=&quot;submit1&quot; name=&quot;btnSubmit&quot; WIDTH=&quot;106&quot; HEIGHT=&quot;54&quot;>
</form>

<h3>New User? </h3>
<a href=&quot;profile.shtml&quot;>Click Here</a>
 
So, you push the submit button and validate the password... How do you get back to the calling page?

You could send the name of the page with the form and redirect back.

Or have I missed something?
 
The question is not how to get back to the calling page.
I guess I want to know how to offer two choices, one based on asp, and one based on html in the same if statement.
I started creating two strings, one if there is a session variable and one if there's not, and to create the login form on the fly in asp with response.writes, but I think I'm about to run into an old familiar problem of not being able to submit from a .write.

I know nearly every username driven website in the world uses this idea of hello username, and I'm sure someone must have been here and done that, and I'd be so appreciative if they could tell me how they did it.

Thanks!
 
do you mean?

<%
IF session(&quot;CandID&quot;) <> &quot;&quot; then
Response.Write &quot;Hello &quot; & session(&quot;CandID&quot;) & &quot;!&quot;
Response.Write &quot;If you are not &quot; & session(&quot;CandID&quot;) & &quot;please &quot;
Response.Write &quot;<a href='default.shtml'>log in.</a>&quot;

ELSE
%>

your HTML code here.....

<% END IF %>

where it write the ASP code or the HTML code?
 
I tried what you suggested, but the submit button won't go anywhere.
Do you know why?
It's not even submitting to itself, i.e. there's no movement at all on the status bar.
Thanks.
 
IS validatePassword.asp in the same folder as the calling page?
 
All the html code used to work just fine all alone on the page default.htm. Everything is in the same folder and it all works great. The only new thing is trying to put it into an if statement.

What's the difference in functionality between post and get, I know they use different methods, querystring and form, and one is sent in the url and one is not, and get can hold much fewer values. But why would any of that make a difference here?

Thanks
 
Thanks for all that info, it doesn't appear to solve my problem.

Does anyone know why a form between two <% %> delimiters is not submitting?

Thanks.
 
Sorry - I meant
%>
<form>
<input type=submit....>
</form>
<%

Does that also not work?
 
I can't see why it doesn't work. I just put your form on one of my development pages. It worked (it pulled up a 404, since I dont have your URL). Have you tried just putting up the form on the page?
 
I know the form works - I think I mentioned that before. I'm trying to move it to a different place and that's where I seem to be having trouble. Did you try it inside an if statement like this:
<%
if session(&quot;CandID&quot;) <> &quot;&quot; then
dim helloString
helloString = &quot;Hello &quot; & session(&quot;CandID&quot;) & &quot;!&quot;
helloString = helloString & &quot;If you are not &quot; & session(&quot;CandID&quot;) & &quot;please &quot;
helloString = helloString & &quot;<a href='default.shtml'>log in.</a>&quot;
Response.Write helloString
else
%>


<h3>Already a member? <br>Login now.</h3>

<table>
<tr>
<td>Username: </td></tr>
<tr>
<td><input id=&quot;text1&quot; name=&quot;txtUserName&quot;></td></tr>
<tr>
<td>Password: </td></tr>
<tr>
<td><input type=&quot;password&quot; id=&quot;password1&quot; name=&quot;txtPassword&quot;></td></tr>
</table>
<input type=&quot;image&quot; src=&quot;images/img_Submit.gif&quot; value=&quot;Submit&quot; id=&quot;submit1&quot; name=&quot;btnSubmit&quot; WIDTH=&quot;106&quot; HEIGHT=&quot;54&quot;>
</form>

<h3>New User? <a href=&quot;profile.shtml&quot;>Click Here</a> </h3>
<%
end if
%>
 
I think I found it. Somewhere in moving the code you blew away the opening form tag.

<form action=&quot;validatePassword.asp&quot; method=&quot;get&quot; name=&quot;frmLogin&quot;>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top