By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,222 Members | 1,728 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,222 IT Pros & Developers. It's quick & easy.

How to persist checkbox selections across recordset pages

P: n/a
Hi All,
I have a large recordset to be displayed on a ASP 3.0 page. I am using
recordset paging for this. For the next and previous link i am passing href
as
<a href=<Page URl>?page=<%= iPageCurrent - 1 %for Previous.
Now when i display the contents i also add a checkbox (for deletion) to each
of the records.
Now user should be able to select one or more checkboxes across pages and
then should be allow to delete all selections together.
Can anyone please point me right directions or give some hints on how to
acheive this.
Thanks and Regards,
Parag
Jul 13 '07 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Not that I know of - unless you change my function mytester to set a
cookie in javascript, that would work as well I think. Then you would
not be passing data around - simply changing a cookie value.
Ther are plent of article on Javascript and Cookies, just punch
"javascript cookies" inbto google.

Regards
Dave

Jul 20 '07 #2

P: n/a
Thanks once again Dave.
Based on the discussions till now I can see three ways to acheive this
1. Querystrings as explianed by your examples. But this means user can the
see values and Querystring has length limitation (though quite long). However
this will work in all browsers
2. Submit the page on click of Next and Prev buttons. store the selections
in hidden field. This i can pass the data without being visible. Not sure how
much performance impact this may have.
3. Cookies - Again here i think the limit is 4K so not sure how many
selections can be stored and also browser needs to support this.
Can you please let me know which would be best option considering following
criterias
1. Performance
2. Data Security
Thanks and Regards,
Parag

"daddywhite" wrote:
Not that I know of - unless you change my function mytester to set a
cookie in javascript, that would work as well I think. Then you would
not be passing data around - simply changing a cookie value.
Ther are plent of article on Javascript and Cookies, just punch
"javascript cookies" inbto google.

Regards
Dave

Jul 20 '07 #3

P: n/a
On Jul 20, 4:44 pm, Parag Gaikwad
<ParagGaik...@discussions.microsoft.comwrote:
Thanks once again Dave.
Based on the discussions till now I can see three ways to acheive this
1. Querystrings as explianed by your examples. But this means user can the
see values and Querystring has length limitation (though quite long). However
this will work in all browsers
2. Submit the page on click of Next and Prev buttons. store the selections
in hidden field. This i can pass the data without being visible. Not sure how
much performance impact this may have.
3. Cookies - Again here i think the limit is 4K so not sure how many
selections can be stored and also browser needs to support this.
Can you please let me know which would be best option considering following
criterias
1. Performance
2. Data Security
Thanks and Regards,
Parag
Submission obviously means that there is no limit to what is stored

Any of these methods would work - yes there are problems with 1 and 3
but it all depends on how many records you expect a user to want to
delete in any one action - if hundreds then dont use querystrings or
cookies. If on a few (less than 40/50) then use any of these methods.

I wouldnt worry about the browser problem with cookies - you can
always check whether they have cookies enabled and if not warn them
and tell them to switch them on - but i dont see how they would get
most websites to work if they have cookies disabled.

Regards
Dave.

Jul 21 '07 #4

P: n/a
Thanks for the response Dave.
I think I would implement one of the following options. However, I am not
100% sure which one to use. Would really appreciate your advice
1. Hiden Field & Submit the Form on click of next and previous button
Pros
- Data is not visible to user
- No storage Limitation
Cons
- Form needs to be submitted resulting some overhead not sure what (main
cause of not being 100% sure)

2. Use cookies to store selection
Pros
- Data is not easily visisble
- Available at client side not sure if boost performance as read write
operation to the cookie file
Cons
- Size limitation. I think t is 4096 bytes or 255 characters.
- The clicking on next button will do saving to cookie and trip to server
though..

Some users might delete more than 50 records...so really bit confused. If I
have to go cookie way then have to restrict users from checking more that say
50 records.
Please let me know your thoughts
Thanks and Regards,
Parag
"daddywhite" wrote:
On Jul 20, 4:44 pm, Parag Gaikwad
<ParagGaik...@discussions.microsoft.comwrote:
Thanks once again Dave.
Based on the discussions till now I can see three ways to acheive this
1. Querystrings as explianed by your examples. But this means user can the
see values and Querystring has length limitation (though quite long). However
this will work in all browsers
2. Submit the page on click of Next and Prev buttons. store the selections
in hidden field. This i can pass the data without being visible. Not sure how
much performance impact this may have.
3. Cookies - Again here i think the limit is 4K so not sure how many
selections can be stored and also browser needs to support this.
Can you please let me know which would be best option considering following
criterias
1. Performance
2. Data Security
Thanks and Regards,
Parag

Submission obviously means that there is no limit to what is stored

Any of these methods would work - yes there are problems with 1 and 3
but it all depends on how many records you expect a user to want to
delete in any one action - if hundreds then dont use querystrings or
cookies. If on a few (less than 40/50) then use any of these methods.

I wouldnt worry about the browser problem with cookies - you can
always check whether they have cookies enabled and if not warn them
and tell them to switch them on - but i dont see how they would get
most websites to work if they have cookies disabled.

Regards
Dave.

Jul 23 '07 #5

P: n/a
To be honest its down to personal prefernce.

Use whichever you like.

If you want to restrict the user to 50 clicks (or however many) then I
have the code to do that if you wish. Alternatively I suppose you
could javascript to count the characters and if over 200 then disallow
any more selections? I dunno.

If it is truly 255 character limit it depends on the size of the ids
of record you want to delete. For example if an ID is "25678655" then
that uses up more characters than "23" obviosuly!
Jul 23 '07 #6

P: n/a
Parag,

Jim is right this will work also , it depends if you mind that the
records are deleted straight away or not.

I assumed you would the user to leisurely scroll through the pages
selecting (and maybe even deselecting) which records to delete before
finally clicking "Delete All checked records" link or something
similar.

It depends on the nature of the application/website.

Regards
Dave

Jul 24 '07 #7

P: n/a
Dave,
Your assumption is correct. I do need the functionality as you mentioned
i.e. Delete all selected records link.
As mentioned in my reply to Jim
The only question in my mind is :- On clicking of the next and prev the form
is submitted. How much impact this has on performance instead of just calling
the same page url (in href) with different PAGE QUERYSTRING value.
Your views on this would be really helpful.
Thanks and Regards,
Parag
"daddywhite" wrote:
Parag,

Jim is right this will work also , it depends if you mind that the
records are deleted straight away or not.

I assumed you would the user to leisurely scroll through the pages
selecting (and maybe even deselecting) which records to delete before
finally clicking "Delete All checked records" link or something
similar.

It depends on the nature of the application/website.

Regards
Dave

Jul 24 '07 #8

P: n/a
I dont personally think there will be a noticable impact on
performance. After all its only one extra fiels your submitting. I
think your worrying about nothing there.

Get on with it and let us know how you get on.

Regards
Dave

Jul 24 '07 #9

P: n/a
"Parag Gaikwad" wrote:
The only question in my mind is :- On clicking of the next and prev the form
is submitted. How much impact this has on performance instead of just calling
the same page url (in href) with different PAGE QUERYSTRING value.
Parag,

I prepared a tutorial for you. This took a long time. I didn't
have the time also to go back and check everything Dave told
you, so I don't if is redundant, or in conflict or what. Please
read this carefully, and I apologise if I'm telling stuff you
already know. I want to be helpful. It is my way of paying
back this newsgroup for helping me with hard problems (and
with easy ones, too.)

Before I start let me go ahead and say this: there are no
performance differences to worry about. Actually, you may
have a lot of work to do. Performance is the least of your
problems.

======================================
Links and the Two Types of Forms
======================================

Clicking on a Submit button when the form is like this...

<form method="get" action="myPage.asp">
<input type="checkbox" name="fileName1" value="delete">
<input type="checkbox" name="fileName2" value="delete">
</form>

-IS- the -EXACT- same thing as clicking on a link where...

<a href="myPage.asp?fileName2=delete">
Next Page
</a>

....assuming that only checkbox #2 is checked.

So, these two are the same. But, this is also the same as
when method="post" except for two things:

(1) The "post" method hides the data so the user will not
see it in the URL. With the href or with method="get",
the data appears on the URL when the user gets to the
next page.

(2) Usually putting the data into the URL is not important,
but it can be if the length limit of URL (the QUERYSTRING
limit) also limits how many rows you can delete. Which
it does. NOTE: method="post" does not put the data
into the URL QUERYSTRING. It puts it into the IP packets
somewhere that more data is allowed than on the URL.

Another difference is you use different ASP functions when
you read the data on the "next page." Here are the functions:

— for forms with method="get" and for links (href="...")

strControlValue = Request.QueryString("strControlName")

— and for forms with method="post"

strControlValue = Request.Form("strControlName")

....where "strControlName" is the value you had in name=""
on the checkbox (or any other input of the form). And the
value="" parameter will go into strControlValue on the "next
page."

======================================
How to Structure an ASP file
======================================

I say "next page" because it is the same page, of course. Go
back and read my examples again. Try to understand every
line. The first thing you do on this page is to determine what
happenned that brought you to this page. Did someone enter
the page name in the address bar of their browser? Did the
user click on "Previous"? On "Next"? You need to figure this
out first thing at the beginning of your asp page.

Now, from a programming point of view, there are many ways
to go through the data once you are back again after clicking
on the "Next" or "Previous" button. Let's talk about that for a
minute.

This is HTML: When you have many checkboxes on a page,
and only some of them are checked, it is these checked ones
that appear in the data. The unchecked boxes are ignored.
The checked boxes appear on the next page as either values
in the Query string or as values in the Form collection.

In the Query string, of course, they look like this:
myPage.asp?name1=value1&name2=value2&name2=value2

In the Form(i) collection, you have to "look" at each Form(i).

Because you don't know the names of the checkboxes that
were checked beforehand, part of what you have to do is to
determine which ones if any were checked. So, you go
through the Query string or through the Form(i)'s until you
get to the end.
======================================
How to Delete a Bunch of Records
======================================

In my previous example, I described how you can
read the Form data from Request.Form(i) and delete the
records. That technique was BACKWARDS from what a lot
of people know. Here, I will show you the "forwards"
way to do this. Both work well. It's personal.
Most programmers would probably prefer the following
technique for your particular problem.

Suppose you named every checkbox with the same name,
and that is name="delete". And each value was something
like value="record1" and value="record2" and like that.
Then what you find when you get to the next page is this...

delete=record1,record2,record3 ...and so forth

(assuming these are the checkboxes you checked)

You can use the VBScript function Split() to make an array
of records_to_delete like this:

Dim strTemp, strRecords
strTemp = Request.Form("delete")
strRecords = Split(strTemp,",")

or if you use href="myPage.asp" (or method="get") then

Dim strTemp, strRecords
strTemp = Request.QueryString("delete")
strRecords = Split(strTemp,",")

....no real differences between them except the limitations in
length you know about already. Split() makes strRecords into
an array containing all the things in strTemp that were
separated by commas.

When you want to delete a file you can do this...

Dim myConnection, iRec, nDeleted
myConnection = Server.CreateObject("ADODB.Connection")
For iRec = 1 to UBound(records)
myConnection.Execute "DELETE * FROM myTable " & _
"WHERE priKey='" & records(iRec) & "';" _
, nDeleted
Next ' delete each record one at a a time

It depends on the database you use, but I think you might be
able to do the following if you want to delete them all at once:

Dim strSQL, iRec, nDeleted
If UBound(strRecords)>0 Then
strSQL = "DELETE * FROM myTable WHERE priKey IN ("
strSQL = strSQL & " '" & strRecords(iRec) & "'"
For iRec = 2 to UBound(strRecords)
strSQL = ", '" & strRecords(iRec) & "'"
Next
strSQL = strSQL & " );"
myConnection.Execute strSQL, nDeleted
Response.Write "<br>" & CStr(nRecords) & _
" were deleted.<br>" & vbCrLf
End If

I tested this for you and it WORKS with an MSAccess database
file (.mdb) assuming that "priKey" is the name of your primary
key and it is a string. Leave out the single quotes if it
is not a string.

If the priKey value were not strings, you could even
do this:

Dim strTemp, strRecords, strSQL, iRec, nDeleted
strTemp = Request.Form("delete")
strRecords = Split(strTemp,",")
If UBound(strRecords)>0 Then
strSQL = "DELETE * FROM myTable " & _
"WHERE priKey IN (" & strTemp & " );"
myConnection.Execute strSQL, nDeleted
Response.Write "<br>" & CStr(nRecords) & _
" were deleted.<br>" & vbCrLf
End If

In fact, if strKey values WERE strings, this should work:

Dim strTemp, strRecords, strSQL, iRec, nDeleted
strTemp = Request.Form("delete")
strRecords = Split(strTemp,",")
strTemp = "'" & Replace(strTemp, ",", "','") & "'"
If UBound(strRecords)>0 Then
strSQL = "DELETE * FROM myTable " & _
"WHERE priKey IN (" & strTemp & " );"
myConnection.Execute strSQL, nDeleted
Response.Write "<br>" & CStr(nRecords) & _
" were deleted.<br>" & vbCrLf
End If
======================================
A Few More Ideas For the Webpage
======================================

You could have on each page THREE buttons. All of
them have name="Choice" loike I mention in my previous
message. One button is to DELETE the records which
are checked, and the other two for the Next and Previous
functions.

Putting it all together, this the new part of your
new asp file:
'
Dim strTemp, strRecords, strSQL, iRec, nDeleted
Dim myConnection
Set myConnection = Server.CreateObject("ADODB.Connection")
myConnection.Open "...Connection String goes here..."
'
'
' First, take care of the records.
'
'
Select Case UCase(Request.Form("Choice"))
Case "DELETE"
'
strTemp = Request.Form("delete")
strRecords = Split(strTemp,",")
strTemp = "'" & Replace(strTemp, ",", "','") & "'"
If UBound(strRecords)>0 Then
strSQL = "DELETE * FROM myTable " & _
"WHERE priKey IN (" & strTemp & " );"
myConnection.Execute strSQL, nDeleted
Response.Write "<br>" & CStr(nRecords) & _
" were deleted.<br>" & vbCrLf
Else
Response.Write "<br>NO records were deleted.<br>" & vbCrLf
End If
End Select
'
'
'
' Next, render the correct page of records.
'
'
Select Case UCase(Request.Form("Choice"))
Case "PREVIOUS"
'
' render the "PREVIOUS" page of records
'
Case "NEXT"
'
' render the "NEXT" page of records
'
Case "DELETE"
'
' render the "SAME" page of records again
'
Case Else ' you got here from ANOTHER page!
'
' render the "FIRST" page of records
'
End Select
'
'
myConnection.Close
Set myConnection = Nothing
Good Luck Parag,

Jim Rodgers


======= An Aside on References =======

By the way, good VBScript and ASP Classic references are
the following:

http://msdn2.microsoft.com/en-us/library/d1wf56tt.aspx
http://www.w3schools.com/vbscript/default.asp
http://msdn2.microsoft.com/en-us/library/ms524664.aspx
http://www.w3schools.com/asp/default.asp

The MSDN references are deteriorating rapidly. MS seems to
be circling the drain under new management. It is fantastically
ironic that the w3schools sites are even on this short list!
Others in this newsgroup will give you more great references.

======================================

Jul 24 '07 #10

P: n/a
Thanks a lot Dave.
I have not got it working both ways the Submit and cookie way.
Once again many thanks for helping me out.
Best Regards,
Parag

Jul 26 '07 #11

P: n/a
Thanks a lot Jim.
Your inputs were very useful.
I have got it working both ways i.e. submit and cookie.
Once again thanks for the help.
Best Regards,
Parag

Jul 26 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.