I have 2 Telerik RaddatePicker controls and the button.
<table class="moss2Search">
<tr>
<td>
<div runat="server">
<telerik:RadDatePicker RenderMode="Lightweight" ID="RadDatePicker1" width="100%" runat="server" DateInput-Label="Boarding Start Date">
</telerik:RadDatePicker>
</div>
</td>
<td>
<div runat="server">
<telerik:RadDatePicker RenderMode="Lightweight" ID="RadDatePicker2" width="100%" runat="server" DateInput-Label="Boarding End Date">
</telerik:RadDatePicker>
</div>
</td>
<td>
<div>
<asp:CheckBox ID="chkMerActive" runat="server" Checked="true"/>Active
</div>
</td>
<td>
<%--<asp:Button ID="btnSeacrh" runat="server" Text="Search" OnClick="btnSearch_Click" OnClientClick="return dateValidation();"/> <br />--%>
<telerik:RadButton RenderMode="Lightweight" runat="server" Text="Search" ID="Button1" OnClick="btnSearch_Click" OnClientClicked="validateDates" AutoPostBack="false"></telerik:RadButton>
</td>
</tr>
</table>
How can I validate these 2 controls for a valid date selected, since the user can type a string value as well?
Use the standard validation that comes with the framework. If the user input can be a date the components will have a value, otherwise null or the default so you can also check against that in a a custom validation rule
Related
I am created a page with update panel and used Asp.net validation controls to be
validated the page is making an issue is "i am straightly going to submit the page
and page gets validated properly then, i am going to click/select any controls on
the page is not get post back"
The below code i am used
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div id="divMyDataManualEntry" runat="server">
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<td style="width: 5%;" valign="top">
<asp:Label ID="lblGeo" Font-Bold="true" runat="server" Text="Geography"></asp:Label><span
class="redtext">*</span>
</td>
<td valign="top" style="width: 15%">
<asp:DropDownList ID="ddlgeo" TabIndex="1" runat="server" CssClass="textbox" Width="100%"
OnSelectedIndexChanged="ddlgeo_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ddlgeo"
ValidationGroup="Submit" InitialValue="-1" ErrorMessage="Select Geography"></asp:RequiredFieldValidator>
</td>
</tr> </table>
<table width="100%" id="BtnContainer" runat="server">
<tr>
<td align="center">
<asp:Button ID="btnSubmit" runat="server" OnClientClick="javascript:return IsValidated();"
ValidationGroup="Submit" CssClass="Keybutton" TabIndex="14" Text="Submit" OnClick="btnSubmit_Click" />
<asp:Button ID="btnreset" runat="server" Text="Reset" CssClass="Keybutton" TabIndex="15"
OnClick="btnReset_click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
I got this modal popup extender but i can't get the files on the FileUpload control. here's my code:
<asp:Button ID="targC" runat="server" Style="display: none;" Text="here" />
<ajax:ModalPopupExtender ID="myExtender" runat="server" BackgroundCssClass="myModalPopupbackGrnd"
TargetControlID="targC" PopupControlID="pnlUserRegNoti" OkControlID="btnDone">
</ajax:ModalPopupExtender>
<asp:Panel ID="pnlUserRegNoti" Width="70%" Style="display: none;" CssClass="myModalPopupload"
runat="server">
<center>
<br />
<br />
<table width="80%">
<tr>
<td>
<center>
<h3><b>Requirements of New Application</b></h3>
<asp:HiddenField ID="validateUploads" runat="server" />
<table>
<tr>
<td>DTI Application Form</td>
<td><asp:FileUpload ID="dtiFileUpload" runat="server" onchange = "return CheckForTestFileDTI();" />
<asp:CustomValidator ID="CustomValidator1" ControlToValidate="dtiFileUpload" runat="server" OnServerValidate="CustomValidator1_ServerValidate" Text="File is too large. Max size is 20MB."></asp:CustomValidator>
</td>
</tr>
<tr>
<td>
<center>
<asp:Button ID="btnDone" runat="server" CssClass="button" Text="Done" OnClick="btnDone_Click" />
</center>
</td>
</tr>
</table>
</center>
</asp:Panel>
i will be using the file on the FileUpload control to upload to WindowsAzure. how can i get the values on the file upload inside the modalpopupextender?
You will need to to retrieve that FileUpload from within the Panel to interact with it in your code behind:
FileUpload dtiFileUpload = (FileUpload)pnlUserRegNoti.FindControl("dtiFileUpload");
Below is the code. Validation summary is never displayed.I trie to add validation group but no help.
<td style="text-align: left">
<asp:TextBox ID="txtccnum" runat="server" Width="100%"></asp:TextBox>
</td>
<td style="text-align: left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server"
ControlToValidate="txtccnum" ErrorMessage="Credit Card # Cannot be empty">*
</asp:RequiredFieldValidator>
</td>
<asp:ValidationSummary ID="ValidationSummary2" runat="server" ShowMessageBox="True"
ShowSummary="False" DisplayMode="BulletList" Width="700px" />
<asp:Button ID="btnapply" Text="NEXT" runat="server" OnClick="btnapply_Click" />
Because ShowSummary="False"
Make ShowSummary ="True"
I added Page.IsValid flag in button click so it will fire the validations and it worked..
I have a textbox which is used to enter the date.Now when the user enters the date in the specified format I have to validate at client side itself,if user gives other than the current date.(current date is the "actual date" when the user makes the entry)
<form id="form1" runat="server">
<div>
<table id="table1" runat="server" border="0" cellpadding="1" cellspacing="2">
<tr>
<td>
<asp:Label id="lblDate" Text="Date" AssociatedControlID="txtDate" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
<asp:CompareValidator id="cmprDate" Text="(Invalid Date)" ControlToValidate="txtDate" Type="Date" Operator="DataTypeCheck" runat="server"></asp:CompareValidator>
</td>
</tr>
</table>
</div>
</form>
try above code. it validate date in client side.
I came across an interesting problem recently. In an ASP.NET Master Page, I have a Login Control and a Google Search Box as shown below:
<div id="searchBox">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td> <asp:TextBox ID="q" MaxLength="100" AutoPostBack="false" runat="server" onclick="ctl00$q.value=''" CausesValidation="False" Text="Google Custom Search" /></td>
<td align="right">
<asp:ImageButton ID="_btnSearch" runat="server" AlternateText="Search" validationgroup="SearchGroup"
CommandName="Search" ImageUrl="~/images/search.gif" OnClick="_btnSearch_Click"/>
</td>
<td width="5px" align="right">
<asp:RequiredFieldValidator ID="_rfvQ" ControlToValidate="q" runat="server" validationgroup="SearchGroup" />
<asp:HiddenField ID="cx" Value="00054535354544538:kmy_69vgpnm" runat="server" />
<asp:HiddenField ID="cof" Value="FORID:11" runat="server" /></td>
</tr>
</table>
</div>
Login Control
<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
<asp:Login ID="Login" runat="server" Width="100%" FailureAction="RedirectToLoginPage" meta:resourcekey="LoginResource1">
<LayoutTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="60px"><asp:Label runat="server" ID="lblUserName" AssociatedControlID="UserName" Text="Username:" meta:resourcekey="lblUserNameResource1" /></td>
<td><asp:TextBox id="UserName" runat="server" Width="95%" meta:resourcekey="UserNameResource2" /></td>
<td width="5px" align="right">
<asp:RequiredFieldValidator ID="valRequireUserName" runat="server" SetFocusOnError="True"
ControlToValidate="UserName" Text="*" ValidationGroup="Login" meta:resourcekey="valRequireUserNameResource1" />
</td>
</tr>
<tr>
<td style="height: 24px"><asp:Label runat="server" ID="lblPassword" AssociatedControlID="Password" Text="Password:" meta:resourcekey="lblPasswordResource1" /></td>
<td style="height: 24px"><asp:TextBox ID="Password" runat="server" TextMode="Password" Width="95%" meta:resourcekey="PasswordResource2" /></td>
<td width="5px" align="right" style="height: 24px">
<asp:RequiredFieldValidator ID="valRequirePassword" runat="server" SetFocusOnError="True"
ControlToValidate="Password" Text="*" ValidationGroup="Login" meta:resourcekey="valRequirePasswordResource1" />
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><asp:CheckBox ID="RememberMe" runat="server" Text="Remember me" meta:resourcekey="RememberMeResource1"></asp:CheckBox></td>
<td align="right">
<asp:ImageButton ID="Submit" runat="server" AlternateText="Login"
CommandName="Login" ImageUrl="~/images/go.gif" ValidationGroup="Login" meta:resourcekey="SubmitResource1" />
</td>
<td width="5px" align="right"> </td>
</tr>
</table>
<div style="border-top: solid 1px black; margin-top: 2px; padding-top: 2px">
<br />
<asp:HyperLink ID="lnkRegister" runat="server" NavigateUrl="~/Register.aspx" meta:resourcekey="lnkRegisterResource1" ForeColor="#104A9D" Text="Create new account"></asp:HyperLink><br />
<asp:HyperLink ID="lnkPasswordRecovery" runat="server" NavigateUrl="~/PasswordRecovery.aspx" meta:resourcekey="lnkPasswordRecoveryResource1" ForeColor="#104A9D" Text="I forgot my password"></asp:HyperLink>
</div>
</LayoutTemplate>
</asp:Login>
</AnonymousTemplate>
<LoggedInTemplate>
<div id="welcomebox">
<asp:LoginName ID="LoginName1" runat="server" FormatString="Hello {0}" meta:resourcekey="LoginName1Resource1" /><br />
<small>
<asp:HyperLink ID="lnkProfile" runat="server" Text="Edit Profile" NavigateUrl="~/EditProfile.aspx" meta:resourcekey="lnkProfileResource1" /><br />
<asp:LoginStatus ID="LoginStatus1" Runat="server" meta:resourcekey="LoginStatus1Resource1" />
</small>
</div>
</LoggedInTemplate>
</asp:LoginView>
The search works fine if the user enters the text in the search text box and clicks the Search Button. However if the user enters the text in the search text box and hits the Enter button, then the validation for the Login control fires off. I want to avoid this since the user just wants to search.
How do I prevent the validation from firing when the user hits enter in the search text box.
Thanks.
You need to read about ValidationGroups. You might also want to change the default button- link text
when till i understand your problem...i think...if you only want to search on enter set search button as a default button and at the same time you want it works and fire no validation for Login text box then set property of search button CauseValidation=false.
If this is your error then will work fine else you describe your problem little in detail