FormView Delete Event
FormView Delete Event
FormView Delete Event
FormView Delete Event
FormView Delete Event
FormView Delete Event FormView Delete Event FormView Delete Event FormView Delete Event FormView Delete Event FormView Delete Event FormView Delete Event FormView Delete Event
FormView Delete Event FormView Delete Event
FormView Delete Event
Go Back  Xtreme Visual Basic Talk > > > FormView Delete Event


Reply
 
Thread Tools Display Modes
  #1  
Old 02-14-2007, 03:25 PM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default FormView Delete Event


I have the following code which will deny users to add or update records if they are not logged in it works great here is the code:

Code:
  If Session("user") = "" And e.NewMode = DetailsViewMode.Edit Then
            Try
                Panel1.Visible = False
                ErrorPanel.Visible = True
                Dim NewLabel As New Label()
                NewLabel.Text = "You do not have permission to edit this record"
                PlaceHolder1.Controls.Add(NewLabel)
            Catch ex As Exception
                ex.Message.ToString()
            End Try

        ElseIf Session("user") = "" And e.NewMode = DetailsViewMode.Insert Then
            Try
                Panel1.Visible = False
                ErrorPanel.Visible = True
                Dim NewLabel As New Label()
                NewLabel.Text = "You do not have permission to add a new record"
                PlaceHolder1.Controls.Add(NewLabel)
            Catch ex As Exception
                ex.Message.ToString()
            End Try

        End If
I want to know the best way to handle the same denial if a person tries to delete a record. On the formview I know I can use the onClick event of the Delete button but I know there needs to be a better way to handle it, i was a more univeral solution so if in the future I try to do the same think with a DetailsView or GridView, etc.

Thanks,
Jason
Reply With Quote
  #2  
Old 02-15-2007, 07:55 AM
wayneph's Avatar
waynephFormView Delete Event wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

If you're using the builtin forms authentication, the ASP.NET engine will redirect users to the login page automatically if they don't have access to the requested page.

Personally, If the user doesn't have permission to delete a record, (or insert/update) I'd never display the button to give them a chance to click on it.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 02-15-2007, 12:19 PM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

There are different levels of permission and I am not using forms authentication.

Some people with a certain permission level can view a page but cannot modify, others cannot view the page at all.. for this reason I didn't want to hide the buttons.... but I can.

What I want to do is place a FindControl on a MasterPage for a control on a specific page... how do I go about doing that?

I want to add

DirectCast(FormView1.FindControl("DeleteButton"), LinkButton).Visible = True

Against a MasterPage LinkButton on_click event.
Reply With Quote
  #4  
Old 02-15-2007, 12:33 PM
wayneph's Avatar
waynephFormView Delete Event wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

I don't think you want that on your MasterPage, do you? If the button only appears on a single Page, the code to hide and show it would be much better if it is in that page's code.

From with in the page, you can get to variables on the MasterPage, but I don't see many reasons for going the other direction. If the control isn't on the MasterPage, it's not going to exist on each page, so you shouldn't need to access it from Master Page code.

I know what I'm trying to say, but I can't tell if I got my point across. My Dr. Pepper is wearing off from lunch. I'm starting to fall asleep.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #5  
Old 02-15-2007, 12:43 PM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

No, I really don't want to do it the way I described... so if I want to hide my Delete Button in the FormView what event do I was to make my DeleteButton Visible=False in?

None of the events that I have placed it in work properly.

I have a login button (for testing purposes) if you click it logins you in and a logout button if you click it logs you out. (At this point what it actually does is sets Session("user") ="" or Session("user")="1"

If the user clicks the Login Button from the Master Part of the page I want the Delete Button to immediately disappear...

I have tried Page OnLoad event and the DataBound event for the FormView but I don't have much luck.

I did get what you were saying, now hopefully you get what I am saying.
Reply With Quote
  #6  
Old 02-15-2007, 12:53 PM
wayneph's Avatar
waynephFormView Delete Event wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Then do it in the Page_Load event of the page where the Delete Button is.

I am pretty sure that the events on the Master Page will be handled before the events on the "enclosed" page. Either that, or you'll have to process the Login (or Logout) in the Master Page and then redirect to the page with the FormView. But that seems a little klunky.

I've officially moved to a DBA position as opposed to Web Development, so I'm not quite as deep in this stuff on a daily basis as I was before.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #7  
Old 02-15-2007, 01:40 PM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

I am using the Page Load Event on the page I have the FormView on. The problem is that it works the first time I click the Login Button, but it does not work if for example I change the SelectedValue of the FormView.

That is why I was thinking that I was using the wrong event...
Reply With Quote
  #8  
Old 02-16-2007, 07:36 AM
wayneph's Avatar
waynephFormView Delete Event wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Is it in an "If Not IsPostBack" block? In that case it would only run on the first request...
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #9  
Old 02-16-2007, 09:25 AM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

Great Point! That solved it... Thanks!
Reply With Quote
  #10  
Old 02-16-2007, 11:37 AM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

FYI, wayne I just wanted to let you know... this still did not work correctly after i tested it a bit... what i ended up doing is placing it in the Page_LoadComplete Event and it works perfectly now.

You were stating which events load first... here they are:

MasterPage child controls
ContentPage child controls
MasterPage Initialization
ContentPage Initialization
ContentPage Load
MasterPage Load
MasterPage child controls load
ContentPage child controls load.
Reply With Quote
  #11  
Old 02-16-2007, 03:54 PM
wayneph's Avatar
waynephFormView Delete Event wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Wow. I had those all out of order. oops. Thanks for clarifying.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
FormView Delete Event
FormView Delete Event
FormView Delete Event FormView Delete Event
FormView Delete Event
FormView Delete Event
FormView Delete Event FormView Delete Event FormView Delete Event FormView Delete Event FormView Delete Event FormView Delete Event FormView Delete Event
FormView Delete Event
FormView Delete Event
 
FormView Delete Event
FormView Delete Event
 
-->