buttons with templates and formview???


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: buttons with templates and formview???

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Posts
    2

    buttons with templates and formview???

    I wish to have the ability to hide certain buttons such as EDIT, DELETE, or ADD based upon the end users permissions.
    I have a table that is read that will determine the end users rights when they enter the form ... but then I need to hide the buttons
    that they don't have the right to use.

    I see that there may be two ways to do this.
    (1) write code to disable the buttons that are default in the templates
    . each time I reenter a template all the buttons reappear if I have disabled them first
    (2) delete the default buttons in the templates and insert buttons outside the formview
    . I can disable the buttons easily here but I can't get the buttons to do the commands which will affect the templates.

    any thoughts or suggestions?????

    thanks

    dave

  2. #2
    Join Date
    Jan 2006
    Posts
    1
    Hi Dave,

    I believe you have a few options:

    1. Keep the buttons in the templates (such as EditItemTemplate), and access them through code via the FindControl method of the FormView:

    Code:
    if (FormView1.CurrentMode = FormViewMode.Edit) // make sure the update template is loaded
    {
        Control foundControl = FormView1.FindControl("UpdateButton");
        if (foundControl != null && !User.IsInRole("My Role"))
            foundControl.Visible = false;
    }
    2. Leave the buttons outside as you mentioned, but instead of using CommandName do form operations in the button click methods:

    Code:
    protected void MyUpdateButton_OnClick(object sender, EventArgs e)
    {
        FormView1.UpdateItem(false); // false = no validation
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!User.IsInRole("My Role"))
            MyUpdateButton.Visible = false;
    }
    3. If possible, simply don't show edit or insert templates, but instead show only the read-only template if they do not have permissions, and do not include any buttons on the read-only template which would allow the user to go into edit or insert mode:

    Code:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (User.IsInRole("My Editor Role"))
            FormView1.ChangeMode(FormViewMode.Edit);
        else if (User.IsInRole("My Creator Role"))
            FormView1.ChangeMode(FormViewMode.Insert);
        // Default FormView mode is read-only
    }
    Of course you could always use a combination of these 3, and at a last resort you can always override the FormView's ItemUpdating or ItemDeleting methods for any last-minute checking, but obviously preventing the actions from occuring in the first place would be the best option.

    Hope this helps,
    Roger

  3. #3
    Join Date
    Jan 2006
    Posts
    29

    Disable the edit, add, and delete button.

    Hi, Roger,

    Your #1 solution to disable the edit, add, and delete buttons on a formview don't work if the formview has paging enabled. The buttons will appeal when you click on one of paging buttons. Do you have any idea to fix this problem

    Thanks.

    Jim

Similar Threads

  1. Formview - Templates - Buttons ???
    By dave.potter@hol in forum ASP.NET
    Replies: 0
    Last Post: 10-07-2005, 07:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center