Link in custom feature only to show when logged in

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
11/1/2012 3:12:06 PM
Gravatar
Total Posts 199

Link in custom feature only to show when logged in

I have the following link in my custom feature, but it shows when logged out and I would like to only show if logged in.

<asp:HyperLink ID="lnkEdit" runat="server" Visible='<%# IsEditable %>' NavigateURL="http://www.domain.com" Text="EDIT" target="_blank"  />

 

I followed the video guestbook tutorial and I thought that "IsEditable" portion would do the trick.  any help is appreciated or if you can guide me to a video or documentation.

11/1/2012 3:19:44 PM
Gravatar
Total Posts 18439

Re: Link in custom feature only to show when logged in

IsEditable is only for users who are in allowed edit roles on the page or feature. IsEditable should only be true when logged in as a user in allowed edit roles unless you've set the edit roles to All Users (which you shouldn't do)

If you want to show something no matter who is logged in you could use Request.IsAuthenticated which is true for any user who is logged in or false if not logged in.

Hope that helps,

Joe

11/2/2012 12:11:59 PM
Gravatar
Total Posts 199

Re: Link in custom feature only to show when logged in

Joe, thanks for the response.

I only have one admin account with edit rights and no other users have edit rights. (it continues to show up for all not logged in)

If I want that link to show up only for a user with edit rights do I have to also write code-behind on page _load to do checking or will it work with just the simple link on the page and the Visible='<%# IsEditable %>' ?

if I hard code Visible="False" it does work

 

 

11/5/2012 12:47:00 PM
Gravatar
Total Posts 199

Re: Link in custom feature only to show when logged in

Joe,

I was able to make this work, but only with code-behind and I am unsure why, but wanted to pass this along:

with this link below on the page and no code-behind properties it will always show logged in or not:

<asp:HyperLink ID="lnkEdit" runat="server" Visible='<%# IsEditable %>' Text="EDIT" NavigateUrl="http://www.domain.com" />

I also had the "IsEditable" display in a label so I could verify TRUE or FALSE -  LblInfoUser.Text = Convert.ToString(IsEditable);

TRUE or FALSE the link showed up.

-----------------------------------

with this link below on the page and the properties set with code-behind it will work correctly:

<asp:HyperLink ID="lnkEdit" runat="server" />

Code Behind:

lnkEdit.Visible = IsEditable;
lnkEdit.NavigateUrl = "http://www.domain.com";
lnkEdit.Target = "_blank";
lnkEdit.Text = "EDIT";

11/5/2012 1:02:27 PM
Gravatar
Total Posts 18439

Re: Link in custom feature only to show when logged in

<%# IsEditable %> is databinding syntax that would be used like in a databound list. If you use it outside a list you would have to call DataBind(); on the module itself in page load.

If not databinding a list it is better to just set it from code behind. 

Hope that helps,

Joe

11/8/2012 8:12:40 AM
Gravatar
Total Posts 199

Re: Link in custom feature only to show when logged in

thanks for the clarification - now it is all starting to make sense.

You must sign in to post in the forums. This thread is closed to new posts.