New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

ReadOnly Option for WebUserControl Edit Form

In some particular cases you may want to present the WebUserControl edit form of your grid instance in read only mode - for example if you would like to acquaint the user with the structure of this edit form without giving him the option to actually edit the data in the grid. This scenario is useful when setting permissions for the users on a regular basis - some of them can be allowed to edit data (through EditCommandColumn) and for the rest you can display a preview column.

The "preview" functionality for user control edit form is easily achievable. To support read only mode for your user control edit form please follow the steps depicted below :

  1. Add GridButtonColumn to your grid instance with CommandName = "Preview".


    <MasterTableView CommandItemDisplay="Top" GridLines="None">
      <EditFormSettings UserControlName="EmployeeDetailsVB.ascx" EditFormType="WebUserControl">
          <EditColumn UniqueName="EditCommandColumn1">
          <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
          <telerik:GridButtonColumn CommandName="Preview" Text="Preview" UniqueName="Preview">
          <telerik:GridBoundColumn HeaderText="TOC" DataField="TitleOfCourtesy" UniqueName="TitleOfCourtesy">
          <telerik:GridBoundColumn HeaderText="FirstName" DataField="FirstName" UniqueName="FirstName">
          <telerik:GridBoundColumn HeaderText="LastName" DataField="LastName" UniqueName="LastName">
          <telerik:GridBoundColumn HeaderText="Hire Date" DataField="HireDate" UniqueName="HireDate">
          <telerik:GridBoundColumn HeaderText="Title" DataField="Title" UniqueName="Title">
  2. Handle the Preview command execution in your ItemCommand event handler and call the SetPreviewMode() method to force the user control in preview mode:


    Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If (e.CommandName = "Preview") Then
            e.Item.Edit = True
            Dim editItem As GridDataItem = e.Item.OwnerTableView.Items(e.Item.ItemIndex)
            Dim ucID = GridEditFormItem.EditFormUserControlID
            Dim MyUserControl As EmployeeDetailsVB = editItem.EditFormItem.FindControl(ucID)
        End If
    End Sub


    private void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        if (e.CommandName == "Preview")
            e.Item.Edit = true;
            GridDataItem editItem = e.Item.OwnerTableView.Items[e.Item.ItemIndex];
            string ucID = GridEditFormItem.EditFormUserControlID as string;
            EmployeeDetailsVB MyUserControl = editItem.EditFormItem.FindControl(ucID) as EmployeeDetailsVB;
  3. In the code-behind of the user control disable all controls which reside in the edit form (except the cancel button) and change the cancel button text to Close.


    public void SetPreviewMode()
        btnUpdate.Visible = false;
        foreach (Control ctrl in this.Controls)
            if (ctrl is WebControl)
                ((WebControl)(ctrl)).Enabled = false;
        btnCancel.Enabled = true;
        btnCancel.Text = "Close";


    Public Sub SetPreviewMode()
        btnUpdate.Visible = False
        For Each ctrl As Control In Me.Controls
            If (TypeOf ctrl Is WebControl) Then
                CType(ctrl, WebControl).Enabled = False
            End If
        btnCancel.Enabled = True
        btnCancel.Text = "Close"
    End Sub
In this article
Not finding the help you need? Improve this article