locked
.net Validation RRS feed

  • Question

  • User1979860870 posted

    Hi

      How to add .net Validations on below Modal .

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" onclick="clearTextBox();">Add New Location</button><br /><br />
            <div class="row">  
                <div class="col-lg-12 "> 
                    <div class="table-responsive">
                        <asp:GridView ID="gvwLocation" OnPreRender="gvwLocation_PreRender" runat="server" 
                        CssClass="table table-bordered table-striped" AutoGenerateColumns="false" OnRowCommand="gvwLocation_RowCommand" OnRowCreated="gvwLocation_OnRowCreated" 
                        BorderWidth="1px"  BorderStyle="None" BorderColor="#DEBA84" HeaderStyle-CssClass="GridHeader" ClientIDMode="Static"
                        EmptyDataText="No Records Found!" EmptyDataRowStyle-ForeColor="Red" EmptyDataRowStyle-CssClass ="gvEmpty" >
                        <HeaderStyle ForeColor="White" Font-Bold="True" BackColor="#428bca"></HeaderStyle>
                        <Columns>
                            <asp:TemplateField HeaderText="Action">
                                <ItemTemplate>
                                    <asp:linkbutton id="btnEdit"  ToolTip="Update Record" CommandName="EditRow" CausesValidation="False" runat="server" CssClass="clslnkbutton"/> 
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Id">
                                <ItemTemplate>
                                    <asp:Label runat="server" ID="lblId" Text='<%#Eval("Id") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Description">
                                <ItemTemplate>
                                    <asp:Label runat="server" ID="lblDescription" Text='<%#Eval("Description") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        </asp:GridView>
                    </div>
                </div>
            </div>
    
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dissmiss="modal"><span aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="Name">Id</label>
                            <input type="text" class="form-control" id="Id" placeholder="Location Id" />
                        </div>
                        <div class="form-group">
                            <label for="Name">Description</label>
                            <input type="text" class="form-control" id="Description" placeholder="Location Description" />
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" id="btnAdd" onclick="return Add();">Add</button>
                        <button type="button" class="btn btn-primary" id="btnUpdate" style="display:none;" onclick="Update();">Update</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    
    </asp:Content>

    Thanks

    Sunday, May 23, 2021 1:59 PM

All replies

  • User475983607 posted

    The Web Forms framework takes advantage of server controls not raw HTML.  I recommend following Web Forms standard programming patterns and features.  Below is the required field validator but there are other validation controls in Web Forms.

    https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.requiredfieldvalidator?view=netframework-4.8

    Sunday, May 23, 2021 2:19 PM
  • User-939850651 posted

    Hi jagjit saini,

    How to add .net Validations on below Modal .

    If you need to use validation controls to validate and filter user input data, the validated must be a server control, so you have to add the attribute runat="server" to the input to make it work.

    Something like this:

          <div>
                <input type="text" class="form-control" id="Id" placeholder="Location Id" runat="server" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="Id" ErrorMessage="Please enter id!"></asp:RequiredFieldValidator>
            </div>

    Of course, you can also choose an existing server control (such as TextBox).

    Best regards,

    Xudong Peng

    Monday, May 24, 2021 10:03 AM