I have an usercontrol, which only must be available for logged in members. I guess there are several way to do this, e.g. place the macro inside a LoginView control.
The have the content inside a asp:panel and then in page load only make it visible to logged in members
protected void Page_Load(object sender, EventArgs e)
{
Member user = Member.GetCurrentMember();
if (user != null)
{
SignupPanel.Visible = true;
}
else
{
SignupPanel.Visible = false;
}
}
You can also check if the current member is null.. It works well this way and you only have to place the macro in the template.. I think it would be the best way to do it this way, if it was a usercontrol, which is placed on several pages, where you don't have to place a loginview in several templates.
Yours will work perfectly if you're using the built-in umbraco membership provider, as soon as you switch to another membership provider, your code will fail...
I'm not sure this is what you meant in your last post, but I guess you can just do the check in your user control itself. No need to have a loginview or panel in that case, just something like this in your user control Load or Init event:
Thanks for your suggestions... I guess there are several way of doing this, some might be better than other..
I'm using the login to let the editors create members, who is allowed to signup for an event (employees can login and choose which events where they can work). Dirk, thanks for your suggestion... I think I only will be using the built-in umbraco membership provider.. but I guess I can use your code as well.
I don't know how much difference the different code example means for the website in this case? But of course when I'm using a couple of lines, it will be better if it can be done in one code line.
Dirk's suggestion for the check is more "generic", so i would use that one, you never know :-)
For the "Visible" property part, it all depends on how you want to design your control. My suggestion was to just set the "Visible" property of the control itself, so you do not need to "encapsulate" it in a login view or in a panel. Just implement the control you need, and add the following line in its Load or Init event:
Yes, I just placed it inside a panel, so I also could hide the surrounding div.. but I see in this way you suggest the usercontrol only is visible, when a member is logged in.
It seem to I need a namespace for the HttpContext?
Show only usercontrol for logged in member
Hi..
I have an usercontrol, which only must be available for logged in members. I guess there are several way to do this, e.g. place the macro inside a LoginView control.
The have the content inside a asp:panel and then in page load only make it visible to logged in members
Or is there a better way to do this?
Bjarne
Hi Bjarne,
Wouldn't it be enough to just place the macro within a loginview control on the template? :-)
All the best,
Bo
Well, that is one way to do it..
You can also check if the current member is null.. It works well this way and you only have to place the macro in the template..
I think it would be the best way to do it this way, if it was a usercontrol, which is placed on several pages, where you don't have to place a loginview in several templates.
Bjarne
Bjarne,
why not using
Yours will work perfectly if you're using the built-in umbraco membership provider, as soon as you switch to another membership provider, your code will fail...
Cheers,
/Dirk
Hi Bjarne,
I'm not sure this is what you meant in your last post, but I guess you can just do the check in your user control itself. No need to have a loginview or panel in that case, just something like this in your user control Load or Init event:
Cheers,
Michael.
Hi..
Thanks for your suggestions... I guess there are several way of doing this, some might be better than other..
I'm using the login to let the editors create members, who is allowed to signup for an event (employees can login and choose which events where they can work).
Dirk, thanks for your suggestion... I think I only will be using the built-in umbraco membership provider.. but I guess I can use your code as well.
I don't know how much difference the different code example means for the website in this case? But of course when I'm using a couple of lines, it will be better if it can be done in one code line.
Bjarne
Hi Bjarne,
Dirk's suggestion for the check is more "generic", so i would use that one, you never know :-)
For the "Visible" property part, it all depends on how you want to design your control. My suggestion was to just set the "Visible" property of the control itself, so you do not need to "encapsulate" it in a login view or in a panel. Just implement the control you need, and add the following line in its Load or Init event:
That way, you do not have to worry where you put your control: it will always do the check.
Cheers,
Michael.
Thanks Michael..
Yes, I just placed it inside a panel, so I also could hide the surrounding div.. but I see in this way you suggest the usercontrol only is visible, when a member is logged in.
It seem to I need a namespace for the HttpContext?
Bjarne
You need System.Web
Cheers,
Michael.
Yep.. :)
It works great :)
Thanks
Bjarne
No prob. Glad you got it working!
is working on a reply...