asp:RequiredFieldValidator with telerik RadDatePicker - asp.net

I using the asp:RequiredFieldValidator with telerik:RadDatePicker but the validation. style not appear ,this is my code:
<telerik:RadDatePicker RenderMode="Lightweight" EnableTyping="false" ID="RDPAddPremisesAndFixedListDate" runat="server">
<DateInput
DateFormat="dd MMM yyyy"
DisplayDateFormat="dd MMM yyyy"
CssClass="general-profile-Date">
</DateInput>
</telerik:RadDatePicker>
<asp:RequiredFieldValidator runat="server" ID="rfvPremisesAndFixedListDate" ControlToValidate="RDPAddPremisesAndFixedListDate"
ErrorMessage="This Field is Empty" ValidationGroup="AddPremises" CssClass="error-msg" />
This screenshot for my fields, all validation style appear except the (telerik:RadDatePicker), what is the problem?

I found the solution, I just added (extra-id="_dateInput_wrapper") in RequiredFieldValidator :)

Related

RegularExpressionValidator and ValidationSummary text displayed but not summary

Can I use clientscript in validation controls while also having my own onblur event? The trouble Im having is getting the validationsummary to be displayed, but the text shows beside each textbox, just not the summary.
Validation controls:
<asp:TextBox runat="server" ID="txtTimeFrameFrom" style="width:50px;font-size:x-small;" onblur="javascript:updatePackageTime1(this);" Text='<%# DataBinder.Eval(Container.DataItem, "TimeFrameFrom")%>'></asp:TextBox>
<asp:RegularExpressionValidator ValidationGroup="grpValidTimeFrame" EnableClientScript="true" Display="Dynamic" Text="<font color='red'>*</font>" ErrorMessage='check format in time from' ControlToValidate="txtTimeFrameFrom" ID="ValidTimeFrameFrom" ValidationExpression="^(1[0-2]|0[1-9]):[0-5][0-9]\040(AM|am|PM|pm)$" runat="server"></asp:RegularExpressionValidator>
<asp:TextBox runat="server" ID="txtTimeFrameTo" style="width:50px;font-size:x-small;" onblur="javascript:updatePackageTime2(this);" Text='<%# DataBinder.Eval(Container.DataItem, "TimeFrameTo")%>'></asp:TextBox>
<asp:RegularExpressionValidator ValidationGroup="grpValidTimeFrame" EnableClientScript="true" Display="Dynamic" Text="<font color='red'>*</font>" ErrorMessage='check format in time to' ControlToValidate="txtTimeFrameTo" ID="ValidTimeFrameTo" ValidationExpression="^(1[0-2]|0[1-9]):[0-5][0-9]\040(AM|am|PM|pm)$" runat="server"></asp:RegularExpressionValidator>
ValidationSummary:
<asp:ValidationSummary ValidationGroup="grpValidTimeFrame" id="ValidationSummary1" runat="server" HeaderText="You received the following errors:"> </asp:ValidationSummary>
When I enter a value in one of the textboxes that cause a validation error, I see a message in the bottom of the browser window (chrome) that seems to indicate a javascript problem (javascript:void(0))
If you set the display to None then it shows the ErrorMessage only in the ValdiationSummary.
Display="None"
And why this? Text="<font color='red'>*</font>". Better keep thing neat and clean and give your validators their own class
CssClass="myValidator"
<style>
.myValidator { color: red; }
</style>

force user select from autocomplete

i am beginner for asp.net . I now facing a problem . How can i force a user to select option from ajax control toolkit autocomplete?
Here is my sample code
<cus:cusTextBox ID="txtCMemberID" runat="server" Action="Edit"
CssClass="inputTextM" OnTextChanged="txtCMemberID_TextChanged"
AutoPostBack="True"></cus:cusTextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server"
ServicePath="~/Module/Common/autoComplete/acLewreMember.asmx"
MinimumPrefixLength="1" ServiceMethod="GetSuggestedStrings"
TargetControlID="txtCMemberID" CompletionInterval="10"
CompletionSetCount="3" EnableCaching="true"
CompletionListCssClass="completionListElement"
CompletionListItemCssClass="listItem"
CompletionListHighlightedItemCssClass="highlightedListItem"
FirstRowSelected="True"
ShowOnlyCurrentWordInCompletionListItem="True">
</asp:AutoCompleteExtender>
As you see the textbox is a custom control. Is that any way to force user to select option from autocomplete?Please provide me a sample code also. thanks
ASP.NET includes a useful feature called a validator.
<asp:TextBox ID="TextBox2" ValidationGroup="Group2" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ErrorMessage="*Required" ValidationGroup="Group2"
ControlToValidate="TextBox2" runat="server" />
<asp:Button ID="Button2" Text="Validate Group2"
ValidationGroup="Group2" runat="server" />
Here is the resource link for msdn: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.aspx
I'm not sure how these work with custom controls as I'm relatively new at asp. They also have a custom validator which might be more suited for your purposes, but like I said. I don't know exactly.
Note: If the client is using an old browser this won't work, so you also want to check on the server that this field isn't empty by using:
if (Page.IsValid)
{
//stuff to do in your event handler
}

Asp.net regex validator does not work

My textbox should contain 8 digits. If not i want to pop up an alert box. But the regualr expression validator does not trigger. Why?
<asp:LinkButton ID="LinkPayment" CssClass="btn mainBtn" runat="server" onclick="LinkPayment_Click" OnClientClick="_gaq.push(['_trackPageview', '/virtualgoal/smspayment']);">Betal ></asp:LinkButton>
<asp:RequiredFieldValidator ID="RequiredCustomersPhone" Display="None" ValidationGroup="ValGroupCustomersPhone" ControlToValidate="CustomersPhone" runat="server" ErrorMessage="Du må fylle inn ditt mobilnummer!"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegExValCustomersPhone" ValidationGroup="ValGroupCustomersPhone" runat="server" ControlToValidate="CustomersPhone" Display="None" ErrorMessage="Telefonnummer må bestå av 8 siffer!" ValidationExpression="[0-9]{8}"></asp:RegularExpressionValidator>
<asp:ValidationSummary ID="ValidationSummary" ShowSummary="False" ValidationGroup="ValGroupCustomersPhone" ShowMessageBox="True" runat="server" />
Add the following code:
ValidationGroup="ValGroupCustomersPhone"
to your linkbutton
Are you trying to validate an empty field? You may need a required field validatior as well. It's a shame there is no 'ValidateEmptyText' field on Regex validators.

AutoPostBack on CheckBox control sometimes fails

If have the below markup.
<asp:checkbox id="chkTVLic" runat="server" text="TV Licence" oncheckedchanged="chkDocs_CheckChanged"
autopostback="true" CausesValidation="false" />
<asp:panel id="pnlTVLic" runat="server" visible="false">
<div class="toggle-item-link1 document-date">
<asp:panel id="pnlTVLicIssueDate" runat="server">
<p>
Please enter the date of issue
</p>
<div class="fm-req">
<asp:textbox id="txtTVLicIssueDate" cssclass="tb size2" runat="server" onblur="return true;"></asp:textbox>
<cc2:calendarextender id="caleTVLicIssueDate" runat="server" targetcontrolid="txtTVLicIssueDate"
popupbuttonid="ibnTVLicIssueDate" popupposition="BottomLeft" animated="true"
format="dd/MM/yyyy">
</cc2:calendarextender>
<asp:imagebutton id="ibnTVLicIssueDate" runat="server" imageurl="../images/img-calendar-day.png"
alternatetext="Calendar" tooltip="Pick Date" cssclass="date-picker" />
<asp:requiredfieldvalidator id="rfvTVLicIssueDate" CssClass="error" runat="server" controltovalidate="txtTVLicIssueDate"
display="Dynamic" errormessage="Required" setfocusonerror="true" validationgroup="TVLic"></asp:requiredfieldvalidator>
<asp:comparevalidator id="cmvTVLicIssueDate" CssClass="error" runat="server" errormessage="Not a valid date"
controltovalidate="txtTVLicIssueDate" operator="DataTypeCheck" type="Date" setfocusonerror="true"
validationgroup="TVLic" display="Dynamic" cultureinvariantvalues="true"></asp:comparevalidator>
<asp:customvalidator id="cuvTVLicIssueDate12Months" CssClass="error" runat="server" controltovalidate="txtTVLicIssueDate"
validationgroup="TVLic" display="Dynamic" onservervalidate="cuvDocIssueDate12Months_ServerValidate"
errormessage="Document must be less than 12 months old."></asp:customvalidator>
</div>
</asp:panel>
<asp:panel id="pnlTVLicApprove" runat="server">
<asp:LinkButton id="lbnTVLicApprove" runat="server" CssClass="screen-hide"
alternatetext="Confirm TV Licence" tooltip="Confirm TV Licence" Text="OK" CausesValidation="false" OnClick="lbnApproveConfirm_Click" />
<asp:imagebutton id="ibnTVLicApprove" runat="server" imageurl="../images/img-accept-doc-off.png"
alternatetext="Approve" tooltip="Approve" cssclass="approval-btn" causesvalidation="true" validationgroup="TVLic" OnMouseDown="HandleApproveClick('TVLic','lbnTVLicApprove');return false;" OnClientClick="HandleApproveClick('TVLic','lbnTVLicApprove');return false;" />
<span class="approval-label">Accept document:</span></asp:panel>
</div>
</asp:panel>
The app is written in c# but i havn't posted any actual code as all the user code related to this markup seems to work fine.
The problem is the CheckBox chkTVLic has causes validation set to false and autopostback set to true. So whatever happens when i check and uncheck the checkbox it should postback. Most of the time this is exactly what it does and the result is to show and hide pnlTVLic when it is checked and unchecked. However if any on the validators within the panel fire, the checkbox does not cause a postback the first time. It will on all subsequent times but never the first. However it should ALWAYS cause a postback. What could be stopping it. Before someone asks there is no use written client side code, everything is pure .net markup and c# code.
I don't see why it shouldn't postback when you check/uncheck the checkbox, but if the only purpose of that checkbox is to hide/unhide a panel, I would rather do it in javascript. Doing a full postback to the server just for hiding some panel seems really bad.
In javascript you can do this to hide the panel:
document.getElementById('<%=pnlTVLic.ClientID%>').display='none';
And this to show it:
document.getElementById('<%=pnlTVLic.ClientID%>').display='block';
It's going to be so much faster and better. Just put a regular checkbox instead of the ASP.NET one and subscribe to the onclick event.
Sorry, one more comment:
I think you are wrong when you say that the checkbox should ALWAYS cause a postback. No, if one of the validators fires inside the panel, the checkbox will not cause a postback until the condition is satisfied.
This is what I did and it worked.
on checkbox onclick event I disabled all the validation controls and immediately did Page_ClientValidate(); and it worked.

Required field validator not working

I have used a required field validator followed by a regular expression validator but the required field validator is not working.....
<asp:TextBox ID="txtSummary" runat="server" TextMode="MultiLine" Width="700px"
CssClass="txtStyle" Font-Names="Arial" MaxLength="1000"
ValidationGroup="Valtxt" TabIndex="2" Rows="4">
</asp:TextBox>
<asp:RegularExpressionValidator ID="regValSummary" runat="server"
ControlToValidate="txtSummary" Display="Dynamic"
ValidationExpression="[^<>&#!]*" ValidationGroup="Valtxt">
Invalid characters(<>&#!) are not allowed
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="reqvalSummary" runat="server"
ControlToValidate="txtSummary" ErrorMessage="Summary is required"
ValidationGroup="Valtxt" Display="Dynamic">
</asp:RequiredFieldValidator>
can anyone sees the problem???
The RequiredFieldValidator is triggered by the client side onchange event. It sounds like you're expecting it to be triggered by the onblur event, such that tabbing away from the textbox would fire the validation.
Before jumping to that, I suspect this is what you are seeing and to validate that it's actually working you need to trigger onchange. To do so, enter some text in the textbox, tab away, tab back to it, clear the textbox, then tab away once more. You should now see the RequiredFieldValidator's error message since it's contents have changed.
Back to the onblur issue. To accomplish that behavior you could add the onblur attribute in your code-behind and have it call the ValidatorValidate(...) JavaScript method as follows:
void Page_Load(object sender, EventArgs e)
{
txtSummary.Attributes.Add("onblur", "ValidatorValidate(" + reqvalSummary.ClientID + ")");
}
Alternately, you could accomplish the same thing in markup. First, add this script block:
<script type="text/javascript">
function rfvBlur() {
var rfv = document.getElementById("<%= reqvalSummary.ClientID %>");
ValidatorValidate(rfv);
}
</script>
Second, update the <asp:TextBox.../> markup by adding onblur="rfvBlur()" so that it now looks like this:
<asp:TextBox ID="txtSummary" runat="server" TextMode="MultiLine" Width="700px" CausesValidation="true"
CssClass="txtStyle" Font-Names="Arial" MaxLength="1000" ValidationGroup="Valtxt"
TabIndex="2" Rows="4" onblur="rfvBlur()" />
Yet another option is to validate the entire ValidationGroup by adding the following attribute to your <asp:TextBox.../> markup (no additional script block needed):
onblur="Page_ClientValidate('Valtxt')"
Adding this line to <appSettings> section of web.config worked for me (I had a problem when all validators stopped working when project was upgraded to .NET 4.5):
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
Source:
http://forums.asp.net/t/1876231.aspx?ASP+Net+4+5+Validation+Controls+not+working+with+AJAX+ToolkitScriptManager1
Why don't you change the regular expression of the "RegEx" validator to check if the textbox is empty instead of use another validator?
Anyway probabily you have not specify ValidationGroup="Valtxt" for the button or the control that raise the postback. Just add ValidationGroup="Valtxt" to the button or the server control that raise the post to the page
I put the following at the top of my btn_Click event handler (to prevent further code execution) and upon 'return', the rfv messages show...
Page.Validate("your validation group");
if (!Page.IsValid)
{
return;
}
<asp:TextBox ID="txtSummary" runat="server" TextMode="MultiLine" Width="700px"
CssClass="txtStyle" Font-Names="Arial" MaxLength="1000"
TabIndex="2" Rows="4">
</asp:TextBox>
<asp:RegularExpressionValidator ID="regValSummary" runat="server"
ControlToValidate="txtSummary" ErrorMessage="Invalid characters(<>&#!) are not allowed" Text="*"
ValidationExpression="[^<>&#!]*" ValidationGroup="Valtxt">
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="reqvalSummary" runat="server"
ControlToValidate="txtSummary" ErrorMessage="Summary is required" Text="*"
ValidationGroup="Valtxt">
</asp:RequiredFieldValidator>

Resources