Is it possible to show the error message of a Regular Expression validator in Asp.net into a message box/ dialog box?
I've tried everything i knew but nothing works for me.
Thanks alot
<form id="form1" runat="server">
<asp:Label ID="lblNameRequired" runat="server" Text="*Name :"></asp:Label>
<asp:TextBox ID="txtNameRequired" runat="server" ValidationGroup="Validation"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="txtNameRequired"
Display="None" ErrorMessage="Name is Required" ValidationGroup="Validation"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="lblGenderRequired" runat="server" Text="*Gender :"></asp:Label>
<asp:DropDownList ID="ddlGenderRequired" runat="server" ValidationGroup="Validation">
<asp:ListItem Selected="True" Value="-1">--Select--</asp:ListItem>
<asp:ListItem Value="0">Male</asp:ListItem>
<asp:ListItem Value="1">Female</asp:ListItem>
</asp:DropDownList>
<asp:CompareValidator ID="CompareValidatorGender" runat="server" ControlToValidate="ddlGenderRequired"
Display="None" ErrorMessage="Gender is Required" Operator="NotEqual" ValidationGroup="Validation"
ValueToCompare="-1"></asp:CompareValidator>
<br />
<asp:Label ID="lblValidation" runat="server" Text="Fields marked with * are required"></asp:Label>
<br />
<asp:Button ID="btnValidate" runat="server" Text="Validate Input" ValidationGroup="Validation" />
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" ValidationGroup="Validation" />
</form>
use the same ValidationGroup text on all validation controls and add a ValidationSummary with the ValidationGroup and ShowMessageBox="true"
Related
I have spent hours on this and read countless threads but not sure what i may be missing to get this to work the way i would like.
I would like to select a file to upload and when the user clicks the button to save the record if there are any validation errors to retain the value of file that was selected to upload.
Heres my markup
<asp:MultiView runat="server" ID="RegisterMultiView">
<asp:View ID="DefaultView" runat="server">
<asp:UpdatePanel ID="upCountryBrands" runat="server">
<ContentTemplate>
Select parent
<asp:RequiredFieldValidator
SetFocusOnError="true"
runat="server" ID="RequiredFieldValidator3"
ControlToValidate="ddlParent" InitialValue="0"
ValidationGroup="MainForm" ErrorMessage="Please select"
Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlParent" runat="server"
OnSelectedIndexChanged="ddlParent_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
Select Child
<asp:RequiredFieldValidator SetFocusOnError="true" runat="server" ID="RequiredFieldValidator2"
ControlToValidate="ddlChild" InitialValue="0"
ValidationGroup="MainForm" ErrorMessage="Please select"
Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlChild" runat="server"
OnSelectedIndexChanged="ddlChild_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
Name
<asp:RequiredFieldValidator SetFocusOnError="true" runat="server" ID="RequiredFieldValidator1"
ControlToValidate="txtName" ValidationGroup="MainForm" ErrorMessage="Please enter your name" Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:TextBox ID="txtName" runat="server" MaxLength="100" />
Enter description of your issue
<asp:TextBox ID="txtIssue" runat="server" TextMode="MultiLine" /> <%--This is a Tiny MCE control--%>
Image 1
<asp:RequiredFieldValidator SetFocusOnError="true" runat="server" ID="rfv1" ControlToValidate="FileUpload1" ValidationGroup="MainForm"
ErrorMessage="Please select an image." Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revFileTypes" runat="server" ErrorMessage="Images only." ControlToValidate="FileUpload1" ValidationExpression=".*\.(gif|jpe?g|png)$"></asp:RegularExpressionValidator>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="false" accept="image/*" ViewStateMode="Enabled" EnableViewState="true" />
<asp:Label ID="lblImageOneStatus" runat="server"></asp:Label>
Image 2
<asp:RequiredFieldValidator SetFocusOnError="true" runat="server" ID="RequiredFieldValidator9"
ControlToValidate="FileUpload2" ValidationGroup="MainForm" ErrorMessage="Images only" Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Images only." ControlToValidate="FileUpload2" ValidationExpression=".*\.(gif|jpe?g|png)$"></asp:RegularExpressionValidator>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="false" class="form-control-file" accept="image/*" />
<asp:Button ID="btnSave" runat="server" Text="Save" ValidationGroup="MainForm" OnClick="btnSave_Click" OnClientClick="txtIssue.triggerSave(false,true);" />
</asp:View>
<asp:View ID="SuccessView" runat="server">
Thanks
</asp:View>
</asp:MultiView>
Couple of notes:
I have an updatePanel surrounding the dropdown so it looks like theres no postback.
I have tried surrounding the FileUpload controls with an UpdatePanel but this made no difference.
I have a TonyMCE control, i dont think this would add a spanner into the works but i have left out the associated Javascript so i can provide if required.
I have tried adding triggers but again this made no difference so i can only assume i am doing something wrong.
How could i ensure when a file is selected using the FileUpload controls and then press Save it retains the value of the file?
I have a question. I have a textarea and 2 textboxes. What I want to do is to check if textarea is filled, other 2 textboxes must not be empty. We can give messagebox like this (please necessary fields must be filled)
This is my code :
<textarea id="txtCustomerRepresentatorOpinion" name="txtCustomerRepresentatorOpinion" runat="server" style="width: 99%"></textarea>
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="txtCustomerRepresentatorOpinion"
ValidationGroup="Save" Text="*" ClientValidationFunction="txtArea" />
<telerik:RadTextBox Width="321px" runat="server" ID="txtCustomerRepresentatorOpinionNameSurname" TextMode="SingleLine" />
<asp:RequiredFieldValidator ID="VldAdi" runat="server" ControlToValidate="txtCustomerRepresentatorOpinionNameSurname"
ValidationGroup="Save" Text="*" ErrorMessage="Lütfen Adı Soyadı giriniz."/>
<telerik:RadDatePicker ID="rdpCustomerRepresentatorOpinionDate" ZIndex="9999" Style="vertical-align: middle;" runat="server">
</telerik:RadDatePicker>
<asp:RequiredFieldValidator ID="VldTarih" runat="server" ControlToValidate="rdpCustomerRepresentatorOpinionDate"
ValidationGroup="Save" Text="*" ErrorMessage="Lütfen Tarihi giriniz.">
</asp:RequiredFieldValidator>
Which side should I use (client side or server side)? How i do this job? Right now, I can show messages but textarea is not working.
Change your textarea into an asp.net TextBox Control with TextMode="MultiLine". Then a RequiredFieldValidator will work.
<asp:TextBox ID="txtCustomerRepresentatorOpinion" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required field" ControlToValidate="txtCustomerRepresentatorOpinion"></asp:RequiredFieldValidator>
Required Field Validator not working properly in gridview
I work in ASP.NET c# and MySQL database.
I need to make the required field of this DropDownList on FooterTemplate, but Required Field Validator not working.
Why ?
My code:
<FooterTemplate>
<asp:ImageButton ID="imgbtnInsert" runat="server" CommandName="Insert" ImageUrl="/images/icon_2.gif"
ToolTip="Add" OnClientClick="return confirm('Confirm?');" />
</FooterTemplate>
<FooterTemplate>
<asp:DropDownList ID="txtIDDTES" runat="server" CssClass="ddl_Class_new">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rtxtIDDTES" runat="server" ControlToValidate="txtIDDTES"
ErrorMessage="***" Text="*" Display="Dynamic" ValidationGroup="Validation1"
SetFocusOnError="true" EnableClientScript="true"></asp:RequiredFieldValidator>
</FooterTemplate>
<asp:ValidationSummary ID="Validation1" ValidationGroup="Validation1" runat="server" ShowMessageBox="true" />
Can you please help me figure out the problem?
Thanks in advance.
Try this :
<form id="form1" runat="server">
<div>
<asp:ValidationSummary ID="ValidationSummaryTop" runat="server" ShowMessageBox="true" ShowSummary="false" />
...
<FooterTemplate>
<asp:DropDownList ID="txtIDDTES" runat="server" CssClass="ddl_Class_new">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rtxtIDDTES" runat="server" ControlToValidate="txtIDDTES"
ErrorMessage="***" Text="*" Display="Dynamic"></asp:RequiredFieldValidator>
</FooterTemplate>
I'm having difficulty trying to access an FileUpload on a event ButtonImagem_Click in the code behind in C# that is within a CompleteWizardStep on a CreateUserWizard.
Where is my code:
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnCreatedUser="CreateUserWizard1_CreatedUser">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" Title="Criar conta">
<ContentTemplate>
<%--...--%>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server" ID="CompleteWizardStep1">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FileUpload1" ErrorMessage=""></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload1" ErrorMessage="Apenas são aceites imagens." ValidationExpression="(.*\.([Gg][Ii][Ff])|.*\.([Jj][Pp][Gg])|.*\.([Bb][Mm][Pp])|.*\.([pP][nN][gG])|.*\.([tT][iI][iI][fF])$)"></asp:RegularExpressionValidator>
<br /><asp:Button ID="ButtonImagem" runat="server" Text="Concluir" OnClick="ButtonImagem_Click" />
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
Found a solution, just needed to add ContentTemplateContainer like this:
FileUpload FileU = (FileUpload)CompleteWizardStep1.ContentTemplateContainer.FindControl("FileUpload1");
My problem is that I can't seem to get my textbox to fire the OnTextChanged event. I also checked and it doesn't seem like it is doing an autopostback despite the fact that it is set to true.
Basically, I am trying to validate the text in the textbox and either enable or disable a button based on the validation status.
Here's my code:
<asp:Panel ID="panelAccessControl" runat="server" Visible="false">
<asp:Panel ID="panelAddMileageRate" runat="server" BorderWidth="2" >
<h2>Add Mileage Rate</h2>
<asp:ScriptManager ID="scriptManagerMileageRate" runat="server" />
<asp:UpdatePanel ID="updatePanelAddMileageRate" runat="server">
<ContentTemplate>
<p>
Purpose:
<asp:DropDownList ID="ddlAddPurpose" runat="server"
AutoPostBack="true" Width="200px"></asp:DropDownList>
<br />
Country:
<asp:DropDownList ID="ddlAddCountry" runat="server"
AutoPostBack="true" Width="200px" >
</asp:DropDownList>
<br />
Effective Date:
<asp:Calendar ID="calAddEffectiveDate" runat="server">
</asp:Calendar>
<br />
Mileage Rate:
<asp:TextBox ID="txtAddMileageRate" runat="server"
AutoPostBack="true" Width="200px"
CausesValidation="true"
ontextchanged="txtAddMileageRate_TextChanged">
</asp:TextBox>
<asp:RegularExpressionValidator
ID="validatorAddMileageRate"
ControlToValidate="txtAddMileageRate" runat="server"
SetFocusOnError="true"
ErrorMessage="Only Numbers allowed"
ValidationExpression="^\d{1,20}(\.\d{0,4})?$">
</asp:RegularExpressionValidator>
</p>
</ContentTemplate>
</asp:UpdatePanel>
<p>
<asp:Button ID="buttonAddSecurityGroup" runat="server"
Text="Submit" onclick="buttonAddSecurityGroup_Click" />
</p>
</asp:Panel>
<asp:Label ID="lblStatus" runat="server" Text=""></asp:Label>
</asp:Panel>
The text box in question is txtAddMileageRate.
Set the EventName property for your txtAddMileageRate AsyncPostBackTrigger to TextChanged.
Add following codes inside your update panel and outside of ContentTemplate
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtAddMileageRate"
EventName="TextChanged" />
</Triggers>
Other sugguestion:
Have you tried looking at the AutoComplete (http://www.asp.net/ajax/ajaxcontroltoolkit/samples/autocomplete/autocomplete) control that is part of the AjaxControlToolKit? Its behaves the same way you want your solution to behave.