Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 31st, 2010, 10:22 AM
Registered User
 
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old January 1st, 2011, 11:57 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
 
Old January 1st, 2011, 10:27 PM
Registered User
 
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
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
 
Old January 2nd, 2011, 06:08 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
 
Old January 2nd, 2011, 09:03 AM
Registered User
 
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
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
 
Old January 2nd, 2011, 09:13 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Great. Glad it's working.

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

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 23rd, 2014, 12:25 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by skachy View Post
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'.
 
Old November 17th, 2018, 04:23 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you elaborate?
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 16:Page 615 try it out Checking Roles with IsUserInRole at Runtime lstew452 BOOK: Beginning ASP.NET 4 : in C# and VB 2 July 5th, 2010 02:20 PM
Chapter 16 Fig 16-11 krsouthern BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 1 July 8th, 2008 12:11 PM
Chapter 6 Roles hdpark BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 7 November 16th, 2007 07:43 PM
Roles.deleteuser 16-26 troubles ufdylan BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 August 2nd, 2007 01:35 PM
Chapter 6 - Roles/Permissions g_rhymes BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 3 June 28th, 2004 11:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.