Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • saif 68 posts 88 karma points
    Jan 25, 2012 @ 11:13
    saif
    0

    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.

     

     

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 25, 2012 @ 11:22
    Jeroen Breuer
    0

    You can get the current Document or Member by using this:

    Member member = new Member(Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]));

    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

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 25, 2012 @ 11:25
    Jeroen Breuer
    0

    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:

    public object value{
      get{
           return ddl_SchoolsList.SelectedValue;}
      set{
           schoolid = (value != null) ? value.ToString() : string.Empty;
    LoadSchoolList(); }
    }

    You can do everything in the get and set of that property. You don't need to use page_load or a postback :).

    Jeroen

  • saif 68 posts 88 karma points
    Jan 25, 2012 @ 11:46
    saif
    0

    Thanks a lot Jeroen.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 25, 2012 @ 11:52
    Jeroen Breuer
    0

    No problem :). You can mark the post which was the most useful as the solution.

    Jeroen

  • saif 68 posts 88 karma points
    Jan 25, 2012 @ 12:43
    saif
    0

    Hi Jeroen,

    I am sorry I could not reference this class.

    Member member =newMember(Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]));

    Please could you tell me which dll file  I need to add from umbraco bin directory.

    regards

    saif

     

     

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 25, 2012 @ 12:47
    Jeroen Breuer
    0

    I think it's in the cms.dll file. The namespace is this: umbraco.cms.businesslogic.member.Member

    Jeroen

  • saif 68 posts 88 karma points
    Jan 25, 2012 @ 13:36
    saif
    0

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

    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.

    regards

    saif

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 25, 2012 @ 13:43
    Jeroen Breuer
    0

    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

  • saif 68 posts 88 karma points
    Jan 26, 2012 @ 10:59
    saif
    0

    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

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 26, 2012 @ 11:06
  • saif 68 posts 88 karma points
    Jan 26, 2012 @ 16:29
    saif
    0

    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.

     


    "

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 26, 2012 @ 16:40
    Jeroen Breuer
    0

    Could you please show the stacktrace of the exception. I don't know what goes wrong now.

    Jeroen

  • saif 68 posts 88 karma points
    Jan 26, 2012 @ 17:35
    saif
    0

     

    [NullReferenceException: Object reference not set to an instance of an object.]
    CustomsControlsForHS.HS.Web.MemberData.GetCurrentMember() +70
    CustomsControlsForHS.MemberDetails.Page_Load(Object sender, EventArgs e) +82
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
    System.Web.UI.Control.OnLoad(EventArgs e) +91
    System.Web.UI.Control.LoadRecursive() +74
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146
    System.Web.UI.Control.LoadRecursive() +146

    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 26, 2012 @ 18:02
    Jeroen Breuer
    0

    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

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft