I have written this code in cshtml file and I was expecting it will write an id on page.
@using umbraco.cms.businesslogic.member @{ Member member = new Member(Convert.ToInt32(HttpContext.Current.Request.QueryString["id"])); var mid = member.Id;
<p>@mid</p> }
Member member =newMember(Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]));
Before using this code I just logged in on my site and I noticed there is no query string in url. I assumed, might be the above line of code is meant to work without query string but it didnot.
please could you recommend any book or documentation where I could read about this.
Thank you for all your support, all your responses have been quick and very useful. I feel slightly uncomfortable in raising all my queries onto the forum will it be possible for you to point me towards some helpful documentation. Alternatively if it is ok with you guys I can carry on posting my queries on the forum.
Are you logged on as a member when you try this? If the member is not logged on you will get this exception. You should add a check if the member is logged on.
bool isLoggedOn = HttpContext.Current.User.Identity.IsAuthenticated;
if (isLoggedOn)
{ //Get the current member }
Get value from custom control!
Hi All,
I have created member Type named HeadTeacher with two properties and their data types are textstring and dropdown custom control.
Here is the code I have written to get the value from dropdown custom contorl.
public partial class _Default : System.Web.UI.Page,umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor {
HSStruct theDoc;
public string schoolName;
public object value{
get{
return schoolName;}
set{
schoolid = (value != null) ? value.ToString() : string.Empty;}}
protected void Page_Load(object sender, EventArgs e){
if (!Page.IsPostBack){
LoadSchoolList(); }}
public void LoadSchoolList(){
cSchool schobj = new cSchool();
theDoc = schobj.GetSchoolsList();
ddl_SchoolsList.DataTextField = "name";
ddl_SchoolsList.DataValueField = "dfesNumber";
ddl_SchoolsList.DataSource = theDoc.DT;
ddl_SchoolsList.DataBind(); }
protected void ddl_SchoolsList_SelectedIndexChanged(object sender, EventArgs e){
schoolName= ddl_SchoolsList.SelectedValue; }
When I created a new member and saved both DFES and Schoolid. The DFES has been saved but schoolName doesn't.
Please could if I am doing something wrong. Any help would be much appreciated.
You can get the current Document or Member by using this:
Than you can get and set properties.
Maybe this wiki can be useful: http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-node-and-document
Jeroen
Hmm sorry needed to look better at your code. You store a value on postback, but you don't have to. That value won't be used. Try this:
You can do everything in the get and set of that property. You don't need to use page_load or a postback :).
Jeroen
Thanks a lot Jeroen.
No problem :). You can mark the post which was the most useful as the solution.
Jeroen
Hi Jeroen,
I am sorry I could not reference this class.
Please could you tell me which dll file I need to add from umbraco bin directory.
regards
saif
I think it's in the cms.dll file. The namespace is this: umbraco.cms.businesslogic.member.Member
Jeroen
Hi Jeroen,
I have written this code in cshtml file and I was expecting it will write an id on page.
@using umbraco.cms.businesslogic.member
@{
Member member = new Member(Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]));
var mid = member.Id;
<p>@mid</p>
}
Before using this code I just logged in on my site and I noticed there is no query string in url. I assumed, might be the above line of code is meant to work without query string but it didnot.
please could you recommend any book or documentation where I could read about this.
regards
saif
The code sample I gave was for a usercontrol which was used as a datatype on a membertype. This won't work in Razor. Maybe this topic can help you: http://our.umbraco.org/forum/developers/extending-umbraco/27626-Accessing-Member-Information
Jeroen
Hi Jeroen,
Thank you for all your support, all your responses have been quick and very useful.
I feel slightly uncomfortable in raising all my queries onto the forum will it be possible for you to point me towards some helpful documentation.
Alternatively if it is ok with you guys I can carry on posting my queries on the forum.
kind regards
saif
I hope this documentation can help:
http://www.nibble.be/?p=20
http://umbraco.miketaylor.eu/2010/08/29/authenticating-new-members/
Jeroen
Hi Jeroen,
I created the control as you expalined in our.umbraco.org/.../27626-Accessing-Member-Information
and I wrote code in control to just test these values are available or not and it works for me.
protected void Page_Load(object sender, EventArgs e)
{
try
{
MemberData md = new MemberData();
if (md.GetCurrentMember() != null)
{
lblMemberId.Text = md.GetCurrentMember().MemberId.ToString();
lblLoginName.Text = md.GetCurrentMember().LoginName;
lblMemberName.Text = md.GetCurrentMember().MemberName;
lblUserRole1.Text = md.GetCurrentMember().RoleName;
lblSchoolName.Text = md.GetCurrentMember().schoolName;
lblDFES.Text = md.GetCurrentMember().dFES;}
else{
lblLoginName.Text = "No records found";}
}
catch (Exception ex){
lblMemberName.Text = ex.Message.ToString();}
when user logged out it throws an exception "Object reference not set to an instance of an object."
which I don't understand why it is happening.
Is there any other way to write code to access the data from MemberData class on any page of the site?
My main objective is to access these values and save them into school table.
thanks in advance.
"
Could you please show the stacktrace of the exception. I don't know what goes wrong now.
Jeroen
Are you logged on as a member when you try this? If the member is not logged on you will get this exception. You should add a check if the member is logged on.
Jeroen
is working on a reply...