Re: GridView and Page.IsValid
Mark Brackett <[email protected]> Wed, 12 Sep 2007 14:35:16 -0400
| Newsgroups | gmane.comp.windows.devel.dotnet.web |
|---|---|
| Message-ID | <[email protected]> |
I think the better way to handle that is to just set
CausesValidation="false" on the delete button. In that spirit, here's my
subclassed GridView:
Public Class ValidatingGridView
Inherits GridView
Protected Overrides Sub OnRowEditing(ByVal e As
System.Web.UI.WebControls.GridViewEditEventArgs)
If IsValid() Then
MyBase.OnRowEditing(e)
Else
e.Cancel = True
End If
End Sub
Protected Overrides Sub OnRowDeleting(ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs)
If IsValid() Then
MyBase.OnRowDeleting(e)
Else
e.Cancel = True
End If
End Sub
Protected Function IsValid() As Boolean
If Not _causesValidation OrElse Page Is Nothing OrElse
Page.IsValid Then
Return True
Else
Return False
End If
End Function
Protected Overrides Function OnBubbleEvent(ByVal source As
Object, ByVal e As System.EventArgs) As Boolean
' Capture validation group and causes validation from the
event source
Dim cmdEventArgs As GridViewCommandEventArgs = TryCast(e,
GridViewCommandEventArgs)
If cmdEventArgs IsNot Nothing Then
Dim cmdSource As IButtonControl =
TryCast(cmdEventArgs.CommandSource, IButtonControl)
If cmdSource IsNot Nothing Then
_causesValidation = cmdSource.CausesValidation
_validationGroup = cmdSource.ValidationGroup
End If
End If
Return MyBase.OnBubbleEvent(source, e)
End Function
Private _causesValidation As Boolean
Private _validationGroup As String
End Class
--MB
> -----Original Message-----
> From: Discussion of building .NET applications targeted for the Web
> [mailto:[email protected]] On Behalf Of Adam Sills
> Sent: Monday, September 10, 2007 11:30 AM
> To: [email protected]
> Subject: Re: [DOTNET-WEB] GridView and Page.IsValid
>
> I think most people (myself included) would like to skip validation
> because
> typically the Delete button should avoid all input validation that is
> associated with the current editing row (since you're deleting the row
> anyway).
>
> Adam..
>
> -----Original Message-----
> From: Discussion of building .NET applications targeted for the Web
> [mailto:[email protected]] On Behalf Of Mark Brackett
> Sent: Monday, September 10, 2007 9:38 AM
> To: [email protected]
> Subject: [DOTNET-WEB] GridView and Page.IsValid
>
> The GridView seems to check Page.IsValid before handling an Update
> (reflected C#):
>
> private void HandleUpdate(GridViewRow row, int rowIndex, bool
> causesValidation) {
> if ((!causesValidation || (this.Page == null)) ||
> this.Page.IsValid) {
> // ... do update to datasource ... //
> }
> }
>
> But not on Delete. It calls Page.Validate() in bool
> HandleEvent(EventArgs e, bool causesValidation, string
> validationGroup),
> but only actually checks Page.IsValid in HandleUpdate(). Personally, I
> think it should be checking IsValid on both Delete and Edit commands
at
> a minimum....
>
> This seems like a huge oversight to me - is everyone hooking a handler
> to GridView.RowDeleting and setting e.Cancel = !IsValid?
>
> ===================================
> This list is hosted by DevelopMentor(r) http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com