+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Manipulating data in custom module

Manipulating data in custom module

8 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    18 Nov 2010
    Link to this post
    Hi,

    I have a generic content custom module which at the moment has four fields.

    Content (built in field)
    Username
    Email
    Password

    When the user clicks "Save" the data is correctly stored. However before it is stored I need to do the following:

    - Create an ASP.NET user using Username, Email and Password
    - Cancel the content from being saved if the email address already exists

    I can see the module has an override for SaveContent - would this be the right place to execute my code? And is there a method available for stopping the data from being saved if an error is encountered, such as a user already existing?

    Thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Nov 2010
    Link to this post
    Hello higgsy,

    Yes, SaveContent is the right place to create the user and inside this method you can cancel the saving if you do not call SaveContent method of the manager. I suggest that you should use a client side validor to see whether the date is set or not and prevent the click on the "save" button which is the better option then canceling the saving when SaveContent method of ContentItemEdit is called.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    18 Nov 2010
    Link to this post
    Hi Ivan,

    Perfect - great answer.

    One last question - how do I use a checkbox as a metafield. When I do so I get the error:

    Meta field control must implement at least ITextControl.

    The checkbox is within the <sf:ContentMetaFields ID="MetaFields" runat="server"> tag.

    Thanks
    higgsy

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Nov 2010
    Link to this post
    Hello higgsy,

    The ASP.NET CheckBox control implements ICheckBoxControl which we support. Please make sure that the metakey is of type Boolean and you use the standard ASP.NET CheckBox control.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    18 Nov 2010
    Link to this post
    Ok - that was my mistake - I hadn't changed the valueType fields in the <metaFields> section of the web.config. Thanks. I know I promised it was the last question, but one very small one!

    My code for saving the content is:

    protected override void SaveContent()
            {
     
                TextBox oUsername = this.FindControl("Username") as TextBox;
     
                if (oUsername != null)
                {
     
                    Membership.CreateUser(oUsername.Text, "testc", "email@email.com");
     
                }
                 
                base.SaveContent();
            }

    However oUsername is always null. How can i get the values of the textboxes/checkboxes etc?

    Thanks
    higgsy


  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Nov 2010
    Link to this post
    Hello higgsy,

    Use a control reference

    protected virtual TextBox UserNameTextBoxControl
          {
              get
              {
                  return base.Container.GetControl<TextBox >("Username", true);
              }
          }


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    18 Nov 2010
    Link to this post
    Hi Ivan,

    Thats what I thought might work, but it gives the error:

    A required control was not found in the template for "~/lib/controls/membersModule/backend/MembersNewView.ascx". The control must be assignable form type "System.Web.UI.WebControls.TextBox" and must have ID "Username".


    Any ideas?

    Thanks
    higgsy
  8. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    18 Nov 2010
    Link to this post
    Hi Ivan,

    This worked for me:

    TextBox oUsername = base.MetaFields.GetControl("Username", true) as TextBox;

    Hope this helps others.

    higgsy
Register for webinar
8 posts, 0 answered