Results 1 to 8 of 8

Thread: why RequiredFieldValidator works everytime..!

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2004
    Location
    India
    Posts
    53

    why RequiredFieldValidator works everytime..!

    hi everyone

    i have used few RFVs( RequiredFieldValidators) in my web form which ahs a datagrid as well. The top section of page allows adding of new records while data grid shows all added records with 'Edit-Cancel-Update' link buttons.

    The problem is that I have used RFVs for the text boxes which r used for adding new record....but whenever even press Update link in the grid...it validated the textboxes as well....which is not required if grid'd links r pressed.

    I know it may have to do with 'Form'...i.e. form submission...but can we somehow distinguish beween the two Submit actions.

    thnx

    yash.
    Yash

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: why RequiredFieldValidator works everytime..!

    You would need to handle the ItemDataBound event of the grid. Found this in a search:

    VB Code:
    1. Public Sub Gridname_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
    2. If e.Item.ItemType = ListItemType.EditItem Then
    3. SetUpdateCommandCausesValidation(e.Item, False)
    4. End If
    5. End Sub
    6.  
    7. Private Sub SetUpdateCommandCausesValidation(ByVal item As DataGridItem, ByVal fEnable As Boolean)
    8. Dim ctrl As Control
    9. Dim btn As Control
    10. If item.HasControls Then
    11. For Each ctrl In item.Controls
    12. If ctrl.HasControls Then
    13. For Each btn In ctrl.Controls
    14. If btn.GetType.Name.Equals("DataGridLinkButton") Then
    15. Dim lnkBtn As LinkButton = CType(btn, LinkButton)
    16. If lnkBtn.Text.Equals(GetUpdateColumnText) Then
    17. lnkBtn.CausesValidation = fEnable
    18. End If
    19. End If
    20. Next
    21. End If
    22. Next
    23. End If
    24. End Sub
    25.  
    26. Private Function GetUpdateColumnText() As String
    27. Dim col As DataGridColumn
    28. Dim colEdit As EditCommandColumn
    29. For Each col In KelompokPelayanan_grdPelayanan.Columns
    30. If col.GetType.Name.Equals("EditCommandColumn") Then
    31. colEdit = CType(col, EditCommandColumn)
    32. Return colEdit.UpdateText
    33. End If
    34. Next
    35. End Function

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: why RequiredFieldValidator works everytime..!

    You need to use a customvalidator - or disable validation on the update link (which from the sounds of it, you do not desire to do because you need to validate something else).

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2004
    Location
    India
    Posts
    53

    Re: why RequiredFieldValidator works everytime..!

    i dont want to validate anything at all on click of linkbuttons...validation needs to be performed on click of Button control which is not a part of the grid, but is available in the form.

    i tried using the code given by 'Mendhak'...but no success so far....actually i coudn't use it properly.

    u said 'disable validation on the update link'...how is this done..?
    Yash

  5. #5
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: why RequiredFieldValidator works everytime..!

    Almost all WebControls has a property called "CauseValidation", if you set that to false then the validation will not be performed. By default it is set to true. I assume you are using Template Column if thats the case then simply set the CauseValidation property of those Update/Edit button to false. That should fix your problem.

    Hope it helps.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2004
    Location
    India
    Posts
    53

    Re: why RequiredFieldValidator works everytime..!

    DataGrid control doesn't have CausesValidation property..
    Yash

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: why RequiredFieldValidator works everytime..!

    Quote Originally Posted by yashsays

    i tried using the code given by 'Mendhak'...but no success so far....actually i coudn't use it properly.
    Explain.

  8. #8
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: why RequiredFieldValidator works everytime..!

    Quote Originally Posted by yashsays
    DataGrid control doesn't have CausesValidation property..
    Not the DataGrid, you need to set the CauseValidation property of the Buttons you place within the DataGrid.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width