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

How to create dynamic page number?? 1

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
Dear All:
One web form in my website need to be filled several times by a single user. I would like to add a page number when user returns to the same page. I tried to use Session variable, it did not work. Anybody has some ideas?


Thanks

Haijun
 
What is the problem you are encountering when using the session variable?
 
Hi Manjulam:
I tried to use this piece of code to regenerate the new number when the page is loaded. But it did not work. Not sure why.

<%
dim PageNo
session(&quot;PageNo&quot;) = 1
session(&quot;PageNo&quot;) = session(&quot;PageNo&quot;) + 1

%>

This is page <%=session(&quot;PageNo&quot;)%>


Haijun
 
hmm. are cookies enabled on the browser?
the Dim for session variables is not valid also
<%
session(&quot;PageNo&quot;) = 1
session(&quot;PageNo&quot;) = session(&quot;PageNo&quot;) + 1
%>
also you need to initiate the counter some how when the page is loaded for it to actual so it.
or else the page will always be more then likely 2 as you made it 1 + 1 = 2

the main detail we need is how are you using this in the pages? are you tracking the users location in regards to incrementing the counter? Just a suggestion: faq183-874
admin@onpntwebdesigns.com
 
Dear Onpnt:
Actually our webform is for evaluation. More than likely, one student needs to evaluate several teachers at a time. The form is the same. I just want to try to make the form a little bit different. So I came up with a page number idea. At least, the student knows how many teachers he or she have evaluated.

I am hoping I state my question correctly.


Thanks for your time

Haijun
 
so what you have is multiple pages for a form? correct
if I understand that right then
page one (initialize the page
session(&quot;PageNo&quot;) = 1

page 2 (increment the counter
session(&quot;PageNo&quot;) = session(&quot;PageNo&quot;) + 1

so what happens if they go page a page? ahh!

in each page you need to specify a new varaible for the page
incrementing off the referer page. like this
page one (initialize the page
session(&quot;PageNo1&quot;) = 1
write to page 1

page 2 (increment the counter
session(&quot;PageNo2&quot;) = session(&quot;PageNo1&quot;) + 1
write to page two
Just a suggestion: faq183-874
admin@onpntwebdesigns.com
 
Actually I have a form in my website which will be used several times. Each time the same page is reload, I need to make the page number change, in order to make it look like a different form. How to make the page number change on the same form when pages are reloaded is my question.
I am sorry I did not clarify my question earlier.

Haijun
 
that's a little clearer. sorry been up wayy too longg
coffee is kicken in though

easy way is to create a hidden field and increment it with each sunbmission

example
<html>
<head>
</head>
<%
Dim pageCount, Curpage
' declare the varaibles needed to do the count
Curpage = request.form(&quot;pageNo&quot;)
' if form value = 0 then we jsut started and set to 1
if Curpage = 0 then
pageCount = 1
else
' else add 1 to count
pageCount = Curpage + 1
end if
%>
<body>
<form action=&quot;pageCounter.asp&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;pageNo&quot; value=&quot;<%=pageCount%>&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
This is page number <%= pageCount %>
</form>
</body>
</html>


sorry I didn't understand earlier.
hope this helps out Just a suggestion: faq183-874
admin@onpntwebdesigns.com
 
Hi,
I would also like to suggests that you use a cookie to store the # of times the user submitted the form. Everytime the user submits a form, the ASP will increment the cookie. This way, it is much simpler to maintain.

However, this will not track if there are more than 1 user using the same PC. If you need to track down the the user level, you'll need to be able to store the count and have a unique ID for the user. Probably in a database. Which becomes more complicated. A simple solution is to use the cookie instead.

regards,
- Joseph
============= ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Shopping --> , Soccer --> ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 
Dear Onpnt:
Thank you for your help. I just copied your code into my ASP progrom. It worked pretty well. But I still have a question for you, hoping I can get answer from you.
The page number will be changed once the user hit the submit button, which run the PageNumber.asp file. I also have a button control in my form, I am hoping it will do the same thing when user clicks it. Unfortunately it did not work. I would like to know what is the difference to click the &quot;Submit type button&quot; and &quot;Button type button&quot;.

Please see the code.

Joseph had the idea to use cookie instead of hidden field. Could you give me a little bit more direction about how to do it? what is the logic behind scence?

Thank.

<html>
<head>
</head>
<%
Dim pageCount, Curpage
' declare the varaibles needed to do the count
Curpage = request.form(&quot;pageNo&quot;)
' if form value = 0 then we jsut started and set to 1
if Curpage = 0 then
pageCount = 1
else
' else add 1 to count
pageCount = Curpage + 1
end if
%>
<body>
<form action=&quot;pageNumber.asp&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;pageNo&quot; value=&quot;<%=pageCount%>&quot;>
<input type=&quot;button&quot; name=&quot;next&quot; value=&quot;NEXT&quot; onClick=&quot;location.href ='pagenumber.asp?Curpage=<%=pageCount%>?'&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
This is page number <%= pageCount %>
</form>
</body>
</html>

 
The difference between the submit and button type is that the button type will not submit the values of the form unless you specify the submit() function somewhere.
How are you submitting the form?

Hence if you never submit the form you will not submit the page number in the hidden field and not increment it. The same will go for he cookie use though.
the process that would go into the use of cookies which would be far more lengthy then the other would be
'Request cookie
pageNu = Request.Cookies(&quot;PageNu&quot;)
'Check to see if a cookie exists
If PageNu = &quot;&quot; then
' if the cookie is not there write it
Response.Cookies(&quot;PageNu&quot;)=&quot;1&quot;
Response.Cookies(&quot;PageNu&quot;).Expires=date
else
'increment the cookie by 1 to add the page number
end if

If cookies are not enabled this will not work. but that these days rarely happens



---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

 
Dear Onpnt:
I know how to get the new page with new page number on it, which will make the same form like different one. Now I come across another problem. I would like to allow user to go to the index page after hitting the submit button.
Let me state my question more clearly. I need to present the same page with new page number on it when user hits the &quot;next&quot; button. But how to allow user to go to different page when they hit &quot;submit&quot; button is my question.

Thank you for your help


Haijun



<html>
<head>
</head>
<%
Dim pageCount, Curpage
' declare the varaibles needed to do the count
Curpage = request.form(&quot;pageNo&quot;)
' if form value = 0 then we jsut started and set to 1
if Curpage = 0 then
pageCount = 1
else
' else add 1 to count
pageCount = Curpage + 1
end if
%>
<body>
<form action=&quot;pageNumber.asp&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;pageNo&quot; value=&quot;<%=pageCount%>&quot;>
<input type=&quot;button&quot; name=&quot;next&quot; value=&quot;NEXT&quot; onclick=&quot;document.form1.submit();&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
This is page number <%= pageCount %>
</form>
</body>
</html>



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top