p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/book-beginning-asp-net-4-c-vb-560/)
-   -   Chapter 16 - Try it Out Checking Roles with IsUserInRole at Runtime (http://p2p.wrox.com/book-beginning-asp-net-4-c-vb/82091-chapter-16-try-out-checking-roles-isuserinrole-runtime.html)

skachy December 31st, 2010 10:22 AM

Chapter 16 - Try it Out Checking Roles with IsUserInRole at Runtime
 
Hi,
I have completed this excersie, but i cannot see the results as expected.

It does not display the delete buttom under the pictures within the album.
I am signed in as a Manager role. When I click on Edit Album link. i see the fields where i can upload new pic in the album , and it does not display any existing pics.

Here is my code in Default.aspx in PhotoAlbums Folder

Code:

protected void ListView1_DataBound(object sender, EventArgs e)
    {
      if (!string.IsNullOrEmpty(DropDownList1.SelectedValue))
      {
        EditLink.NavigateUrl = string.Format("~/ManagePhotoAlbum.aspx?PhotAlbumId={0}", DropDownList1.SelectedValue);
        EditLink.Visible = true;
      }
      else
      {
        EditLink.Visible = false;
      }


Here is the code in ManagePhotAlbum.aspx
I debugged this page by putting a break point on switch statement, and saw that it does not go pass the switch statement, that means the deletebutton visible is not executed at all.

Code:

protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
  {
    switch (e.Item.ItemType)
    {
      case ListViewItemType.DataItem:
        Button deleteButton = (Button)e.Item.FindControl("DeleteButton");
        deleteButton.Visible = Roles.IsUserInRole("Managers");
        break;
    }
  }

Thanks for your help in advance
Suhail

Imar January 1st, 2011 11:57 AM

Hi there,

Quote:

I am signed in as a Manager role
Code:


deleteButton.Visible = Roles.IsUserInRole("Managers");

Could the difference in the name of the role (Manager versus Managers) be the problem here?

Cheers,

Imar

skachy January 1st, 2011 10:27 PM

Quote:

Originally Posted by Imar (Post 267106)
Hi there,


Code:


deleteButton.Visible = Roles.IsUserInRole("Managers");

Could the difference in the name of the role (Manager versus Managers) be the problem here?

Cheers,

Imar

Hi Imar,

Thanks for the reply.
I mean I am signed in as a Manager user and "Managers" is checked for this user under Roles.
I also changed the code as you suggested to the following and saved/ran, but i get the same results.
Code:

deleteButton.Visible = Roles.IsUserInRole("Manager");
The switch statement fails so it does not even get to the above statement
Code:

switch (e.Item.ItemType)
Can you please suggest what else could be wrong?

Suhail

Imar January 2nd, 2011 06:08 AM

Quote:

and it does not display any existing pics.
Ah, so maybe the pictures are never bound. Could this be it:

Code:


"~/ManagePhotoAlbum.aspx?PhotAlbumId={0}"

Notice how you have Phot instead of Photo. If you use PhotoAlbumId in the target page, the album ID isn't passed correctly to the target page.

Hope this helps. You only posted a small bit of your code so I can only make some guesses. If this doesn't solve it, please post the complete code for the ManagePhotoAlbum.aspx page and the full URL you see in the address bar of the browser.

Imar

skachy January 2nd, 2011 09:03 AM

Quote:

Originally Posted by Imar (Post 267123)
Ah, so maybe the pictures are never bound. Could this be it:

Code:


"~/ManagePhotoAlbum.aspx?PhotAlbumId={0}"

Notice how you have Phot instead of Photo. If you use PhotoAlbumId in the target page, the album ID isn't passed correctly to the target page.

Hope this helps. You only posted a small bit of your code so I can only make some guesses. If this doesn't solve it, please post the complete code for the ManagePhotoAlbum.aspx page and the full URL you see in the address bar of the browser.

Imar

Thanks a lot Imar.
As you correctly pointed out. The problem was in PhotoAlbum/Default.aspx. I was missing a "o" after "t" in PhotoAlbumId={0}

Code:

EditLink.NavigateUrl = string.Format("~/ManagePhotoAlbum.aspx?PhotoAlbumId={0}", DropDownList1.SelectedValue);
It works great now. Thanks again

Suhail

Imar January 2nd, 2011 09:13 AM

Great. Glad it's working.

BTW: no need to quote the entire previous message when replying....

Cheers,

Imar

FrugalRacer November 23rd, 2014 12:25 PM

Quote:

Originally Posted by skachy (Post 267128)
Thanks a lot Imar.
As you correctly pointed out. The problem was in PhotoAlbum/Default.aspx. I was missing a "o" after "t" in PhotoAlbumId={0}

Code:

EditLink.NavigateUrl = string.Format("~/ManagePhotoAlbum.aspx?PhotoAlbumId={0}", DropDownList1.SelectedValue);
It works great now. Thanks again

Suhail

Sorry for resurrecting a long-dead thread, but I did the exact same thing! I left the 'o' off of 'Photo'.

yortogagna November 17th, 2018 11:13 AM

Facing Same Error Almost
 
Was trying plex.software/ with the same Tutuapp string, but breaking in Vidmate middle. Did you get any solution yet?

Regards,
Smith

Imar November 17th, 2018 04:23 PM

Can you elaborate?


All times are GMT -4. The time now is 02:07 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.