disable the Add New Link

4 posts, 1 answers
  1. TippCityTom
    TippCityTom avatar
    14 posts
    Member since:
    Sep 2008

    Posted 23 Jan 2009 Link to this post

    how can you disable the Add New Link until edit is updated   I don't want user to be able to add a record if they are currently updating one at the same time   I assume this is done via RadGrid1_ItemCommand


    Using:

     

    <CommandItemSettings AddNewRecordText="Add new record" AddNewRecordImageUrl="Images/AddRecord.gif"

     

     

    RefreshText="Refresh" RefreshImageUrl="Images/Refresh.gif" />

     

  2. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 23 Jan 2009 Link to this post

    Hello Thomas,

    I suggest you test the following approach:
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
        bool editMode = e.Item.OwnerTableView.OwnerGrid.EditIndexes.Count > 0; 
        bool insertMode = e.Item.OwnerTableView.IsItemInserted; 
        if ((e.CommandName == RadGrid.InitInsertCommandName ||  
            e.CommandName == RadGrid.EditCommandName ||  
            e.CommandName == RadGrid.EditAllCommandName ||  
            e.CommandName == RadGrid.EditSelectedCommandName) 
            && (insertMode || editMode)) 
            e.Canceled = true

    Let me know whether this helps.

    Best regards,
    Daniel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. TippCityTom
    TippCityTom avatar
    14 posts
    Member since:
    Sep 2008

    Posted 23 Jan 2009 Link to this post

    thanks for the fast response, that particular answer I could not get to work for me and I assume it is because I set AllowAutomatic Inserts/Updates =  false

    do you have one for scenario where they are done manually, sorry should have clarified that initially?

    in my case IsInEditMode is always false

  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 27 Jan 2009 Link to this post

    Hi Thomas,

    Can you try with the following approach and see if it is helpful.

    CS:
     protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
          // this will fire when the edit button is clicked and disable the AddNewRecord button when the Grid is in edit mode
            if ((e.Item is GridEditableItem)&&(e.Item.IsInEditMode)) 
            { 
                foreach (GridCommandItem cmdItm in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)) 
                { 
                    LinkButton Addbtn = (LinkButton)cmdItm.FindControl("InitInsertButton"); 
                    Addbtn.Enabled = false
                    Button btn = (Button)cmdItm.FindControl("AddNewRecordButton"); 
                    btn.Enabled = false
                } 
            } 
       } 



    Thanks
    Shinu.
Back to Top