+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Modifying User Administration

Modifying User Administration

9 posts, 0 answered
  1. Jason Hedges
    Jason Hedges avatar
    22 posts
    Registered:
    16 Jul 2009
    27 Jul 2009
    Link to this post
    I am trying to modify /Sitefinity/Admin/CmsAdmin/Users.aspx to give a specific Role a limited set of functionality for managing users. Basically, this Role is allowed to manage some roles but not all of them. I am hooking into events for the primary GridView and the Actions DropDownList in the page OnInit. Everything has been working except when I try to create a new user, I get the following error:

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Security.WebControls.ManageUsers.SetMessage(MessageMode msgMode) +54
       Telerik.Security.WebControls.ManageUsers.OnPreRender(EventArgs e) +359
       System.Web.UI.Control.PreRenderRecursiveInternal() +80
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
    

    It does not error if I remove my event handlers from the page OnInit. Here's what I'm basically doing to hook the events:

    //Main GridView
    GridView gvUsers;
    gvUsers = (GridView)manageUsers.Controls[0].FindControl("GridView1");
    if (gvUsers != null)
    {
        gvUsers.RowDataBound += new GridViewRowEventHandler(gvUsers_RowDataBound);
    }

    //Assign to Roles drop down
    DropDownList actionsList;            
    actionsList = (DropDownList)manageUsers.Controls[0].FindControl("actionsList");
    if (actionsList != null)
    {
        if (actionsList.Items.Count > 0) //in case this is already populated with items
        {
            actionsList_DataBound(null, EventArgs.Empty);
        }
        else
        {
            actionsList.DataBound += new EventHandler(actionsList_DataBound);
        }
    }

    Any idea what might be causing the error?

    Thanks!
    Jason
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 Jul 2009
    Link to this post
    Hi Jason Hedges,

    Please try adding your logic in OnPreRender method. This should fix the problem and fire the events.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Jason Hedges
    Jason Hedges avatar
    22 posts
    Registered:
    16 Jul 2009
    27 Jul 2009
    Link to this post
    This does fix the error I was getting but introduces another problem. I'm filtering the GridView by handling the RowDataBound event and setting some rows  to Visible=false. However, clicking the alphabet links in the command panel allows the user to get access to these hidden rows. Any suggestion there?

    Thanks,
    Jason
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Jul 2009
    Link to this post
    Hello Jason Hedges,

    Debug the code and see whether the breakpoint is reached when clicking alphabet links. I took a look at the implementation. It turned out that SearchByLetter method is private and cannot be accessed. In this method all users are bound again and this could be the problem.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Jason Hedges
    Jason Hedges avatar
    22 posts
    Registered:
    16 Jul 2009
    28 Jul 2009
    Link to this post
    I stepped through in debug and my RowDataBound event handler is not reached again after clicking the alphabet links. If clicking a letter is rebinding the grid, why doesn't it raise that event again?

    Thanks,
    Jason
  6. Jason Hedges
    Jason Hedges avatar
    22 posts
    Registered:
    16 Jul 2009
    28 Jul 2009
    Link to this post
    I was able to filter the grid by handling the Grid's PreRender event. This gets fired regardless of whether the user clicks an alphabet link. I'd still like to know why the alphabet links aren't causing the grid to raise the RowDataBound event.

    Thanks,
    Jason


    Jason Hedges

    Developer, MCPD, MCTS
    Smooth Fusion
    www.smoothfusion.com
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jul 2009
    Link to this post
    Hi Jason Hedges,

    "In this method all users are bound again and this could be the problem."

    The GirdView is already bonded when you press any letter. Then the event is not fired. You can subscribe for  manageUsers.Load event and then find gvUsers and subscribe for RowDataBound event.

        protected override void OnInit(EventArgs e) 
        { 
            base.OnInit(e); 
            manageUsers.ModeChanged += new EventHandler(manageUsers_ModeChanged); 
            manageUsers.CreatedRole += new RoleCreatedEventHandler(manageUsers_CreatedRole); 
            manageUsers.Load += new EventHandler(manageUsers_Load); 
        } 
        void manageUsers_Load(object sender, EventArgs e) 
        { 
            //Main GridViewGridView gvUsers; 
            gvUsers = (GridView)manageUsers.Controls[0].FindControl("GridView1"); 
            if (gvUsers != null
            { 
                gvUsers.RowDataBound += new GridViewRowEventHandler(gvUsers_RowDataBound); 
            } 
        } 


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. Dan
    Dan avatar
    24 posts
    Registered:
    02 Oct 2012
    13 Jan 2011
    Link to this post
    I created an event handler to tie into the RowDataBound event as you described, and it works fine for the alphabet links, but when I click to edit or create a user, and then click the "All Users" button to go back to the list (or the back / cancel buttons on the form), my RowDataBound handler doesn't work.  When I step through the code, the GridView is null at the time the manageUsers.Load event fires.  I'm guessing it has something to do with the mode change from edit view to list view.  Any ideas how I can get this working?

    Thanks, DanO
  9. Dan
    Dan avatar
    24 posts
    Registered:
    02 Oct 2012
    13 Jan 2011
    Link to this post
    Just solved the problem by putting the RowDataBound event handler registration code in a common function and calling it from the manageUsers_ModeChanged handler (in the ManageUsers.Modes.List case) as well as from the original location (manageUsers_Load).

    -DanO
Register for webinar
9 posts, 0 answered