Re: Repeater paging problem

From: Robert Koritnik (robert.koritnik.removethis_at_avtenta.si)
Date: 09/22/04


Date: Wed, 22 Sep 2004 18:38:36 +0200

Ok. First about your "authentication". You are somehow triing to do
something that's already there out of the box. User Forms authentication and
you won't have to take care of the user checking on every page. Ok. You
don't have to check for authentication on your pages, because asp.net does
that for you. So when you get to any page that is under security, you may be
shure the user is authenticated. Check some samples in MSDN. Maybe you'll
have to create your own security principal to satisfy your needs.

About checkboxes. The way things should be done: Create checkboxes inside
your repeater but handle event OnCheckedChange. In that handler you take
care of creating that comma separated checkbox texts. Event will fire only
on those that will be changed from false to true. ok. If you change the page
before deleting, the selected ones should stay there. So on creation you
should parse on the serverside that string (make a private property that
saves its value to ViewState instead of Session) and if the text is in it,
check on creation that checkbox.

About delete button. Action events ALWAYS happen AFTER changed events so
your comma separated string property will already be ready when your
delete_click event fires. Ok. How to avoid your two page process? Instead of
client-server back and forth data transfers, you create a LinkButton to
handle this. Ok. Serverside click will fire normally. And when it does just
delete the records that were selected. But IN the codebehind (the best place
would be Page_Load event handler) you add to your linkbutton an attribute to
be like this:

lbDeleteSelected.Attributes.Add("onclick", "javascript: if (!confirm('You
really blahblah...')) window.event.returnValue=false;");

This should do the trick...

Doing it this way, you won't need no Session variable, no iteration thru
items, no GET fields. Things will be faster and more efficient. Code will be
easier to understand and event driven.

Ok. One more hint. There is a possibility when a user presses the F5 button
the whole dela will happen again and the records are already deleted... What
could you do? After deletition, just put a sentance like this:
Response.Redirect(your_page_address)

You can obtain address from Request object, and if I'm not mistaken also
from the Response object. Or you can write it staticly.

One more hint. :) The code you do in your Page_load event... You have two
possibilities. You can inherit the Page class or create a web user control
(UserControl class) that will handle redirection for administrators. Ok. And
don't parse string into int and change it back to string. That makes your
code run slower. Rather use string.Equals() method... Session per se (I
think so, someone correct me if I'm wrong) isn't serialized. You don't have
to use notation Session["whatever"].ToString(). you can easily cast to
(string) if you've put a string inside of it. And creating so many session
variables for the same thing is nonsence. If you have more variables that
are somehow connected (like username, password, user display name, roles
collection, etc.) Just create an object that has all that and put that
object in Session. This way you wont have to operate with so many Session
variables, but with just one object.

I think there's enough hints for one message.

I suggest you to read a lot MSDN and some valuable internet sites like
www.dotnet247.com, www.gotdotnet.com, www.asp.net etc... You will see how
much you'll learn out of other people experience.

-- 
RobertK
{ Clever? No just smart. }