Server side validation from RadGrid

5 posts, 2 answers
  1. Andy Green
    Andy Green avatar
    120 posts
    Member since:
    Jul 2009

    Posted 15 Mar 2010 Link to this post

    Hi Team

    I have a RadGrid with a Edit Form Setting of Template and a load of textboxes. Some of these have Requiredfield validator on them and this all works fine.

    What I also need to do is a server side lookup on a value and not submit the data if that value exists. So I fill out my form, hit insert (its a new record) and if I single step the code it detects the duplicate value, but how do I then return to the radgrid, in insert mode, and show the error (I have a label control set to visible = false and want to show it.)

    What is happening is the radgrid closes the form and I looses my data, and the label is never seen.

    Andy
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Mar 2010 Link to this post

    Hi,

    Try setting the e.Canceled to true to cancel the closing of the Insert form on duplicate entry .

      protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
        { 
          if("Duplicate exists"
            { 
             e.Canceled = true
            } 
              
        } 

    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    120 posts
    Member since:
    Jul 2009

    Posted 16 Mar 2010 Link to this post

    Thanks Princy

    Andy
  5. Andy Green
    Andy Green avatar
    120 posts
    Member since:
    Jul 2009

    Posted 16 Mar 2010 Link to this post

    How would I disable some of he text box control on edit, but have them available for insert.

    I have the follwoing code but it disables the control all the time, I cant differentiate between edit and insert.
        Private Sub rgLocations_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgLocations.ItemCreated  
     
            'disable the Location Code for edits as its the PK  
            If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then  
                Dim UpdatedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
                Dim LocationCodeAs TextBox = CType(UpdatedItem.FindControl("txtLocationCode"), TextBox)  
                LocationCode.Enabled = False 
            End If  
     
        End Sub 

    Andy
  6. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Mar 2010 Link to this post

    Hi,

    Please  have a look at the link below which discusses on the same:
    Distinguish edit/insert mode on ItemCreated/ItemDataBound

    Princy
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017