Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web application that someone else wrote, I'm not a web developer but am looking to put a requirement on 1 field in the web page that forces the user to enter a value (i.e. can't leave the field blank).

Below is the section of the .aspx page that i'm trying to make required. Suggestions on how to do this as I've tried a few things but nothing seems to make the field required. Would you need the entire syntax from the .aspx page or is what is below enough to identify where/how to make the field required?

</div>
                <div class="col-md-3 col-sm-3 col-xs-3">
                    <label>
                        <asp:Label ID="lblSiteId" runat="server">321@@Site</asp:Label></label>
                    <div class="pvWrapper">
                        <asp:TextBox ID="SiteId" TabIndex="9999" runat="server" Columns="15" AutoPostBack="True"></asp:TextBox><uc1:PV ID="SiteId_PV" TabIndex="9999" runat="server"></uc1:PV>
                    </div>
                </div>


What I have tried:

I've tried various versions of required="true" as well as just required within the
Posted
Updated 11-Aug-20 18:05pm

1 solution

In Asp.Net webform , you need to use validator server controls depending upon the requirement like
1.For required fiild:- RequiredFileldValidator
2.Comparison :- CompareValidator
3.To match a string:- RegularExpression validator
4.Custom Logic :- custom validator
 
Share this answer
 
Comments
wdodds20 12-Aug-20 0:19am    
As far as the validation goes I just want to validate that something is entered into the field other than possibly a space. Sounds like that would be a RegularExpression validator?
wdodds20 12-Aug-20 1:08am    
I got it somewhat close by using a function RegExp and then applying that to the SiteId field, however the way the page is written if a user selects or pastes a value in any of the other 4 fields VendId, PONbr, etc. then the data is returned to the page regardless of the SiteId being blank.

Any ideas?

<%@ Register TagPrefix="uc1" TagName="MenuBar" Src="MenuBar2.ascx" %>
<%@ Register TagPrefix="uc1" TagName="PV" Src="PV.ascx" %>

<%@ page language="vb" autoeventwireup="false" inherits="ReQlogicFW.Receipt, ReQlogicFW" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Src="PVDate.ascx" TagName="PVDate" TagPrefix="uc2" %>



<title>Receiving














function CheckMyText(sender, args) {
var compare = RegExp("\\d{1,}");
args.IsValid = compare.test(args.Value);
return;
}








<uc1:menubar id="MenuBar1" runat="server">
<asp:scriptmanager id="ScriptManager1" runat="server" enablescriptglobalization="true">





<asp:label id="LblPageHeading" runat="server"><% =Trim(Session("Page_Title")).ToString() %>









<asp:label id="lblUserId" runat="server">237@@Requester

<asp:textbox id="UserId" tabindex="9999" runat="server" columns="15" visible="True"><uc1:pv id="UserId_PV" runat="server">




<asp:label id="lblSiteId" runat="server">321@@Site

<asp:textbox id="SiteId" tabindex="9999" runat="server" columns="15" autopostback="True" required=""><uc1:pv id="SiteId_PV" tabindex="9999" runat="server">

<asp:customvalidator id="CustomValidator2" runat="server" errormessage="Error!" controltovalidate="SiteId" validateemptytext="true" clientvalidationfunction="CheckMyText">




<asp:label id="lblVendId" runat="server" designtimedragdrop="560"> 106@@Vendor

<asp:textbox id="VendId" tabindex="9999" runat="server" columns="15"><uc1:pv id="VendId_PV" tabindex="9999" runat="server">





<asp:checkbox id="AutoPrint" tabindex="9999" runat="server" text="1167@@Auto print receipt">







<asp:label id="lblReqNbr" runat="server">280@@ReqNbr

<asp:textbox id="ReqNbr" tabindex="9999" runat="server" columns="15"><uc1:pv id="ReqNbr_PV" tabindex="9999" runat="server">




<asp:label id="lblPONbr" runat="server">232@@PONbr

<asp:textbox id="PONbr" tabindex="9999" runat="server" columns="15" autopostback="True"><uc1:pv id="PONbr_PV" tabindex="9999" runat="server">



<asp:button cssclass="reqlogic-btn" id="Preview" tabindex="9999" runat="server" text="117@@Apply Filter">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900