Copied to clipboard

Flag this post as spam?

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


  • Ric Carey 50 posts 93 karma points
    Jan 31, 2012 @ 12:55
    Ric Carey
    0

    Writing to the database from the Front End

    Ive got a form posting back in razor however im a bit confused as to how i can send the data from the form to the umbraco database. Any ideas as usuall will be appreciated.

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Jan 31, 2012 @ 13:08
    Dan Diplo
    0

    You would do this in the same way you would in any standard ASP.NET page. Razor is just standard C# code so you can call any methods you like in the .NET framework or in your own external libraries.

    To be clear, though, are you wanting to store your data in a custom table within the Umbraco database? If so, I would personally write a class library in Visual Studio and then compile it and place the assembly in your /bin folder (it would make sense to put it in a unique namespace, too). In your class library write a (probably) static method that accepts the parameters for your form and then call this method from your Razor script (like you would do any other method). That way the logic is all in your class and not within your Razor file.

    Note that Umbraco 4 has it's own SQL Helper class that abstracts away data access (since Umbraco can work with different databases). This is in umbraco.BusinessLogic.Application.SqlHelper

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Jan 31, 2012 @ 13:11
    Dan Diplo
    0

    NB. You should also investigate using Umbraco Contour form builder. It makes creation of forms very easily and all data is stored in a database without the need for any programming. It's well wroth 99 EUR.

  • Ric Carey 50 posts 93 karma points
    Jan 31, 2012 @ 13:18
    Ric Carey
    0

    Well i was hoping to be able to write to the members database. Ive got an asp.net default form:

    <script runat="server">

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        Roles.AddUserToRole(CreateUserWizard1.UserName, "SiteMembers");
    }

    protected void CreateUserWizard1_ContinueButtonClick(object sender, EventArgs e)
    {
        Response.Redirect("/members.aspx");
    }

    </script>

    <asp:CreateUserWizard ID="CreateUserWizard1" OnContinueButtonClick="CreateUserWizard1_ContinueButtonClick" OnCreatedUser="CreateUserWizard1_CreatedUser" runat="server">
        <WizardSteps>
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"></asp:CreateUserWizardStep>
            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server"></asp:CompleteWizardStep>
        </WizardSteps>
    </asp:CreateUserWizard>

    however that just generates a table and i want to style it in my own way. I was also hoping to reuse the razor code for writing to other sections of umbraco such as the content nodes.

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Jan 31, 2012 @ 13:39
    Dan Diplo
    0

    You can use methods in the ASP.NET membership provider - see http://our.umbraco.org/wiki/how-tos/membership-providers

  • Ric Carey 50 posts 93 karma points
    Jan 31, 2012 @ 13:59
    Ric Carey
    0

    cheers ill have a play around.

Please Sign in or register to post replies

Write your reply to:

Draft