locked
User Control validation that uses data from database on a web page RRS feed

  • Question

  • User-1798917180 posted

    Hi,

    We have asp.net web application and we created user control for date dropdowns. We use this date user control on all web pages. On some pages, we need to validate whether selected date is weekend or holiday as per our database table. This validation is done in user control custom validator control server side event getting data from database.

    All those pages have Telerik RadGrid controls which are client bound. 

    When user selects holiday as date and does data entry into Grid and clicks on submit button, validation fails and grid clientside bind happens erasing all entries.

    How can I make user control to have client side validation. Some said using JSON get data from database and validate. 

    Please share code or suggest options.

    Thank you,

    Thursday, March 26, 2020 4:07 PM

Answers

  • User475983607 posted

    Telerik is a paid for development solution.  Most users on this forum do not have Telerik.  You should ask this question on a Telerik support forum and provide source code that reproduces this issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 26, 2020 4:15 PM

All replies

  • User475983607 posted

    Telerik is a paid for development solution.  Most users on this forum do not have Telerik.  You should ask this question on a Telerik support forum and provide source code that reproduces this issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 26, 2020 4:15 PM
  • User1535942433 posted

    Hi Spunny,

    Accroding to your description,I don't understand your requirment clearly.I'm guessing that you want validation the date from database and return the result.I suggest you could use  CustomValidator control post data to service and validate whether the date is hoilday then return the result using ajax.Or do you want to add  client customvalidator to  validate the date and  server fetch data.

    Since you don't post more about your codes,I create a demo.

    More details,you could refer to below codes:

    ASPX:

     <script src="Scripts/jquery-3.4.1.min.js"></script>
        <script type="text/javascript">
            function ClientValidate(source, arguments) {
                var date = arguments.Value;
                var data = { "date": date };
                console.log(JSON.stringify(date));
                $.ajax({
                    url: "2165351.aspx/valication",
                    type: "post",
                    dataType: 'json',
                    data: JSON.stringify(data),  
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        var data = new Date("2020-03-28");
                        var dt = data.getDay();
                        console.log(data);
                        if (dt == 6 || dt== 0) {
                            alert("weekend");
                        }
    
                    },
                    
                }) 
            }
        </script>
      
    
    <div>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:CustomValidator
                    ID="CustomValidator1" runat="server"
                    ErrorMessage="Not an even number!"
                    ControlToValidate="TextBox1"
                    ClientValidationFunction="ClientValidate"></asp:CustomValidator>
            </div>

    Code-behind:

     [System.Web.Services.WebMethod]
            [HttpPost]
            public static string valication(string date)
            {
                var dv = new List<date>() {
                    new date(){datetime=DateTime.Parse("2020-03-28")},
                    new date(){datetime=DateTime.Parse("2020-03-27")},
                };
                date = dv.ToString();
                return date;
            }
            public class date
            {
                public DateTime datetime;
                public bool checkv;
    
            }

    Best regards,

    Yijing Sun

    Friday, March 27, 2020 6:02 AM