Required Field Validator not working properly in gridview - c#

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>

Related

Retain selected file after postback with FileUpload

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?

Editing database from front-end, asp.net c#

I'm able to update the database fine, but how do I get the current information extracted from the database into the Edit textboxes.
This is my current code:
<asp:ListView ID="ListView1" runat="server" DataSourceID="Details">
<ItemTemplate>
<div class="col-xs-11">
<asp:Label ID="passwordname" runat="server"
Text="Current Password:" />
<asp:Label ID="password" runat="server"
Text='<%# Eval("Password") %>' />
</ItemTemplate>
</asp:ListView>
<asp:TextBox ID="editpassword" runat="server"
placeholder='<%# Eval("Password") %>' Text="New Password">
</asp:TextBox>
How do I get the textbox editpassword to show the current password stored?
Did you try binding the Value of the asp:TextBox?
Also, instead of using Eval(), consider model binding.
<asp:ListView ID="ListView1" runat="server"
DataSourceID="Details" ItemType="MyNamespace.MyClass">
<asp:TextBox ID="editpassword" runat="server"
Value='<%# BindItem.Password %>' Text="New Password">
</asp:TextBox>
Setting up databind for a listview using c#

Get an object (FileUpload) from a CompleteWizardStep

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");

Regular Expression Validator Error in Dialog Box in Asp.net

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"

Ajax calendar not working

I am using Ajax Calendar for date picker. when i click the calendar image the page will get postback but the calendar popup windows is not getting popup. How to resolve this problem?
Thanks in advance.
<asp:TextBox ID="txt_FromDate" runat="server" AutoPostBack="True"
ontextchanged="txt_FromDate_TextChanged>
</asp:TextBox>
<cc1:CalendarExtender ID="cal_FromDate" PopupButtonID="ibtnFromDate"
runat="server" TargetControlID="txt_FromDate"
Format="MM/dd/yyyy">
</cc1:CalendarExtender>
<asp:ImageButton ID="ibtnFromDate"
ImageUrl="~/_layouts/images/PayrollImages/calendar.gif"
ImageAlign="Bottom" runat="server"/>
Try This:
<asp:TextBox ID="btn1" runat="server">
</asp:TextBox>
<asp:ImageButton ID="img1" runat="server"
ImageUrl="~/_layouts/images/PayrollImages/calendar.gif"/>
<cc1:CalendarExtender ID="calendar1" runat="server" PopupButtonID="img1"
TargetControlID="btn1" Enabled="True">
</cc1:CalendarExtender>
<asp:TextBox ID="txtDOB" runat="server" Width="50%"></asp:TextBox>
<cc1:CalendarExtender ID="txtDOB_CalendarExtender" runat="server"
TargetControlID="txtDOB"
Format="MM/dd/yyyy" PopupButtonID="imgDate"
PopupPosition="BottomLeft">
</cc1:CalendarExtender>
<asp:Image ID="imgDate" AlternateText="Image Date"
ImageUrl="~/Images/Calendar.png" runat="server" />
try this,
<asp:TextBox ID="txt_from" placeholder="MM/DD/YYYY" runat="server"
AutoPostBack="True" ontextchanged="txt_from_TextChanged">
</asp:TextBox>
<cc1:CalendarExtender ID="txt_from_CalendarExtender" runat="server"
Format="MM/dd/yyyy" Enabled="True"
TargetControlID="txt_from">
</cc1:CalendarExtender>
no need to use image button for calendar.
You are just missing a Property of CalanderExtender PopupButtonID. try the following
<asp:TextBox ID="txt_FromDate" runat="server" AutoPostBack="True"
ontextchanged="txt_FromDate_TextChanged">
</asp:TextBox>
<asp:ImageButton ID="ibtnFromDate"
ImageUrl="~/_layouts/images/PayrollImages/calendar.gif"
ImageAlign="Bottom" runat="server"/>
<cc1:CalendarExtender ID="cal_FromDate" PopupButtonID="ibtnFromDate"
runat="server" PopupButtonID="ibtnFromDate"
TargetControlID="txt_FromDate" Format="MM/dd/yyyy">
</cc1:CalendarExtender>

Categories

Resources