How to disable textbox only in editform template

9 posts, 1 answers
  1. Luis
    Luis avatar
    23 posts
    Member since:
    Mar 2009

    Posted 09 Mar 2010 Link to this post

    Hello
    I got a Radgrid
    I have a textbox within the FormTemplate
    and i want to disable the textbox but only in editmode not in insertmode

    i use this code:
       If e.Item.IsInEditMode Then
          Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
          Dim txt As TextBox = (TryCast(item.FindControl("txt"), TextBox))
          txt.Enabled = False
        End If

    can somebody help me please

    thanks
  2. Yeroon
    Yeroon avatar
    87 posts
    Member since:
    Oct 2012

    Posted 09 Mar 2010 Link to this post

    Maybe the ItemCommand event works for you:

    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)  
        If e.CommandName = RadGrid.InitInsertCommandName Then  
              'enable textbox here
        ElseIf e.CommandName = RadGrid.EditCommandName Then  
              'disable textbox here          
              
        End If  
    End Sub 


    Use it in the OnItemCommand event of the Grid:

    OnItemCommand

     

    ="RadGrid1_ItemCommand"

     

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Luis
    Luis avatar
    23 posts
    Member since:
    Mar 2009

    Posted 09 Mar 2010 Link to this post

    thanks
    but bring me another problem
    how i to find the textbox i want to diseable?

    i can find it but in the itemdatabound event
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Mar 2010 Link to this post

    Hi,

    You can distinguish between the Insert and edit modes in the ItemDataBound/ItemCreated events and enable /disable the textbox accordingly:

     Private Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles  RadGrid1.ItemCreated 
       If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then 
          Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
          Dim txt As TextBox = (TryCast(item.FindControl("txt"), TextBox))
          If e.Item.OwnerTableView.IsItemInserted Then 
                txt.Enabled=True
          Else 
                txt.Enabled=False
          End If 
       End If 
      End Sub   


    Thanks,
    Princy
  6. Luis
    Luis avatar
    23 posts
    Member since:
    Mar 2009

    Posted 10 Mar 2010 Link to this post

    Thanks a lot :)
  7. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 25 Jan in reply to Luis Link to this post

    Hi there, My question is how to conditionally enable/disable all Text Boxes in Edit Form. I have a form with more than 50 Text Boxes.

    I can manually enable/disable one by one.  Is there any way I can disable them from code such as:

     

    foreach (Control ctrl in item)
    {
            if (ctrl is TextBox)
               ((TextBox)ctrl).Enabled = false;
    }
     

    if so, which event? Pre_Render or Item_Created or any other event. Thanks

     

    gc_0620

     

  8. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 28 Jan Link to this post

    Hello,

    Generally, if you are using RadTextBoxes, you can access all of them on the page using a similar implementation to the following approach and disable each of them:
    Copy Code
    function pageLoad() {
        var radControls = $telerik.radControls;
        for (var i = 0; i < radControls.length; i++) {
            if (Telerik.Web.UI.RadDatePicker.isInstanceOfType(radControls[i])) {
                var picker = radControls[i];
                picker.set_minDate(new Date());
            }
        }
    }

    Or this can be also achieved on server-side with recursion.


    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  9. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 28 Jan in reply to Eyup Link to this post

    Hi Eyup,

    I can't disable all Texboxes in pageload event. I would like to enable/disable TextBoxes based on user security rights. Ex: Admins are allowed to make changes, viewers can't make any changes. That's why I am using Item Databound event to verify/validate security credentials.

    Thanks

    gc_0620

  10. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 02 Feb Link to this post

    Hi,

    Then you can access the TextBoxes depending on your chosen EditMode and toggle their visibility accordingly:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017