Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
Old January 1st, 2011, 11:57 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,046
Thanks: 80
Thanked 1,580 Times in 1,557 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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
Old January 2nd, 2011, 06:08 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,046
Thanks: 80
Thanked 1,580 Times in 1,557 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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
  #5 (permalink)  
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
Reply With Quote
  #6 (permalink)  
Old January 2nd, 2011, 09:13 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,046
Thanks: 80
Thanked 1,580 Times in 1,557 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!
Reply With Quote
  #7 (permalink)  
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'.
Reply With Quote
  #8 (permalink)  
Old November 17th, 2018, 11:13 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2018
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Facing Same Error Almost

Was trying with the same string, but breaking in middle. Did you get any solution yet?

Regards,
Smith
Reply With Quote
  #9 (permalink)  
Old November 17th, 2018, 04:23 PM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,046
Thanks: 80
Thanked 1,580 Times in 1,557 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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03:20 PM
Chapter 16 Fig 16-11 krsouthern BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 1 July 8th, 2008 01: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 02:35 PM
Chapter 6 - Roles/Permissions g_rhymes BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 3 June 28th, 2004 12:03 PM



All times are GMT -4. The time now is 04:42 AM.


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