 |
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
|
|
|
|

December 31st, 2010, 10:22 AM
|
Registered User
|
|
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

January 1st, 2011, 11:57 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

January 1st, 2011, 10:27 PM
|
Registered User
|
|
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
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
|

January 2nd, 2011, 06:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

January 2nd, 2011, 09:03 AM
|
Registered User
|
|
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
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
|

January 2nd, 2011, 09:13 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Great. Glad it's working.
BTW: no need to quote the entire previous message when replying....
Cheers,
Imar
|

November 23rd, 2014, 12:25 PM
|
Registered User
|
|
Join Date: May 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by skachy
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'.
|

November 17th, 2018, 04:23 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you elaborate?
|
|
 |
|