Copied to clipboard

Flag this post as spam?

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


  • Peter Reynolds 4 posts 24 karma points
    Jan 24, 2012 @ 02:48
    Peter Reynolds
    0

    Custom section field validation

    Hi,

    I have made a custom section. I would like to make some fields mandatory and wondering if there some api calls I can use to help make the validation summary appear at the top when errors occur, and be style appropriately. I've search alot but minimal results of interest appear. Some were related to document types and other areas but not custom sections which seemed different.

    What I have so far....

    Thanks for any help!



    <umbraco:UmbracoPanel ID="ContentPanel" runat="server" hasMenu="true" Text="Edit Organisation" >

    <div style="margin: 10px 0px 10px 0px; text-align: left;" class="error">
    <h3>There were errors:</h3>
    <asp:ValidationSummary runat="server" ID="vs1" />
    </div>

    <umbraco:Pane ID="Pane1" runat="server">
    <umbraco:PropertyPanel ID="PPanel1" runat="server" Text="Name">
    <asp:TextBox ID="OrgNameField" runat="server" MaxLength="100" CssClass="guiInputText guiInputStandardSize"></asp:TextBox>
    <asp:RequiredFieldValidator ErrorMessage="errormessage" ControlToValidate="OrgNameField"
    runat="server" EnableClientScript="false" Display="Dynamic" />
    </umbraco:PropertyPanel>

    <umbraco:PropertyPanel ID="PPanel2" runat="server" Text="State">
    <asp:DropDownList ID="StateField" runat="server" CssClass="guiInputText guiInputStandardSize"
    DataValueField="StateID" DataTextField="StateName" AppendDataBoundItems="true">
    <asp:ListItem Value=""></asp:ListItem>
    </asp:DropDownList>
    </umbraco:PropertyPanel>

    </umbraco:Pane>
    </umbraco:UmbracoPanel>
    </asp:Content>
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 24, 2012 @ 05:48
    Tom Fulton
    1

    Hi Peter,

    There aren't any APIs that I know of for this, but I've done it the same way as you and mimiced the umbraco styles using this:

    <asp:Panel runat="server" ID="errorPanel" Visible="false" Style="margin: 10px 0px 10px 0px; text-align: left;" CssClass="error">
    <h3>Please correct the following errors</h3>
    <asp:ValidationSummary runat="server" ID="vs1"/>
    </asp:Panel>

    (set the Panel to visible if errors)

    HTH,
    Tom 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 24, 2012 @ 06:49
    Jeroen Breuer
    1

    Tom is right. Best way is to use the default ValidationSummary and don't give it a ValidationGroup. Here is how I do it (which looks exactly like the default error message).

    <style type="text/css">
        .validationSummaryTop
        {
            margin-top: 10px;
            margin-bottom: 10px;
        }
    </style>

    <%--ValidationSummary--%> <asp:ValidationSummary runat="server" DisplayMode="BulletList" ID="ValidationSummaryDetails" CssClass="error validationSummaryTop" HeaderText="<h3>The data has not been saved because there are some errors you need to fix first:</h3>"></asp:ValidationSummary> 

    Jeroen

  • Peter Reynolds 4 posts 24 karma points
    Jan 24, 2012 @ 22:42
    Peter Reynolds
    0

    Righto thanks guys, will stick with that approach.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 25, 2012 @ 04:45
    Tom Fulton
    0

    Jeroen's looks better :)  For some reason I didn't think you could put HTML tags (<h3>) in the HeaderText property so I wrapped in a panel instead.

    -Tom

  • Scott 95 posts 277 karma points
    Feb 27, 2013 @ 11:28
    Scott
    1

    I believe that there is a better way to do this, and sorry I know this is an old thread but look at the following:

    in the button save click event at the top put in this (here tabControl is the TabView id.

    Remember to disable clientside validation either pr. page or pr. control.

    aspx file

    <umb:TabView runat="server" ID="tabControl" AutoResize="true" Width="600" />
    <umb:Pane runat="server" ID="pPane" Text="Heading">
    <umb:PropertyPanel ID="ppPropertyPanel" runat="server" Text="Label">
    <asp:TextBox ID="txtTextBox" runat="server" CssClass="guiInputText guiInputSmallSize" Width="50px"></asp:TextBox>
    <asp:RangeValidator ID="rvTextBox" runat="server" Text="*" ControlToValidate="txtTextBox" ErrorMessage="Label must be a positive number between 0 and 100" SetFocusOnError="true" Display="Dynamic" MinimumValue="0" MaximumValue="100" Type="Double" EnableClientScript="false"></asp:RangeValidator>
    </umb:PropertyPanel> 
    </umb:Pane> 

    code behind

    if (!Page.IsValid)
    {
    foreach (umbraco.uicontrols.TabPage tp in tabControl.GetPanels())
    {
        tp.ErrorControl.Visible = true;
        tp.ErrorHeader = ui.Text("errorHandling", "errorButDataWasSaved");
        tp.CloseCaption = ui.Text("close");
    }
    }
    else if (Page.IsPostBack)
    {
    // hide validation summaries
    foreach (umbraco.uicontrols.TabPage tp in tabControl.GetPanels())
    {
        tp.ErrorControl.Visible = false;
    }
    }

    And that's it actually!

    Any comments are apreciated.

Please Sign in or register to post replies

Write your reply to:

Draft