Add Required Field Support To Custom Web Control?
Mar 18, 2010How to add required field support to custom web control? I can't see any doc on that?
View 2 RepliesHow to add required field support to custom web control? I can't see any doc on that?
View 2 RepliesI'm trying to create a custom control that has a dropdown list and a required field validator in it.I've got as a far as being able to set the error message if the control fails to validate, but I can't actually get it to validate, not can I figure out how to call a .Validate method server side. This is driving me nuts!
To create my control, I followed the article here I ran the text box example through, and I can get that to validate without any problems, so I then went through and created a new set of class files relating to a drop down list.Anyone got any thoughts, or hints as to what might be wrong, or where I should start looking?
Here is a code for my web form control
<asp:TextBox runat="server" ID="txtUsername"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtUsername" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:CustomValidator OnServerValidate="checkUsername" ID="CustomValidator1" runat="server" ControlToValidate="txtUsername" EnableClientScript="true" ClientValidationFunction="checkUsername" ErrorMessage="CustomValidator"></asp:CustomValidator>
Client side validation
<script type="text/javascript">
function checkUsername(source,args){
alert("test");
/* alert(args.Value);
[Code]....
I'm trying to add a validation support to DropDownList by creating a custom control inheriting from DropDownList:
public class MyDropDown: DropDownList, INamingContainer
{
private const string ValidatorID = "Validator";
private RequiredFieldValidator _validator;
[Code]....
My class implements INamingContainer because I wanted to avoid naming conflicts. Unfortunately when I try using this control I get the following exception:
Unable to find control id 'MDD' referenced by the 'ControlToValidate' property of 'MDD_Validator'
This is happening beause for INamingContainer FindControl(NamingContainerId) returns null.
When I remove INamingContainer implementation and set validator ID in the following way:
_validator.ID = String.Format("{0}_{1}", ID, ValidatorID);
Everything is working fine, and id given to Validator is the same as it would be inside Naming container.
But is there a way to accomplish this WITH INamingContainer ?
How to add a required field validator to Dropdown list.I had tried can anyone let me know how to do it.
i took the dropdown list control and i binded the control using sqldatasourece to disaply the values from the database.when i am validatiing using Required field validator i am unable..
I want to disable the requiredfield validator control for the textbox based on some condition of a variable
if(var==null)
{
//Activate it
}
else
{
//disable it
}
I have usercontrol which has required field validation in it. I have 2 instances of this usercontrol in single web page . Now if I click button on first usercontrol the validation messages are fired for 2 user controls. But only the required fields of that user control has to be fired.
View 5 RepliesHow can we use required field validator on User Control in aspx page*strong text*
I have one user control that have one drop down. I am using this control on my page. I want to use required field validator on this drop down.
I am working on a custom menu control, partially as a learning exercise, and I am having trouble with Visual Studio's IntelliSense support for it in markup view.The conventional ASP.NET menu allows you to place an arbitrary depth of <asp:MenuItem/> elements under the <Items>...</Items> element. I'm after the same behaviour for my menu.Mine unfortunately does not. VS insists on an empty tag:
<hn:AwesomeMenu runat="server" ID="menu">
<Items />
</hn:AwesomeMenu>
[code]...
I created some required field validators and a validation summary control. When I get an error it displays next to the control its validating and also inside the validation summary control. I only want the error to display in one place; inside the validation summary control. I tried making the required field validator invisible but then it didn't display anywhere.How can I get the errors to only display in the validation summary control? There is no need to display them twice it just clutters up the page.
View 3 RepliesI want to apply styles on the message (i.e. Name field is required) display by the asp.net required field validator control.
Styles=border, padding, background-color, font-color, font-weight, img etc
And I also want highlight the border or asp.net textbox and asp.net dropdown list with which this control is associated.
RequiredFieldValidator does not have style property !
How can I use required field validators in the insert item template in a listview control? The empty fields in the insert item template are preventing the user from deleting or updating ay other row.
View 6 RepliesI have created user control inside update panel but validation is not working.. and i have 10 these usercontrols so how can i do validation on save..?
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UpTextBox.ascx.cs" Inherits="Retail.control.UpTextBox" %>
<asp:UpdatePanel ID="UpdatePaneltxt" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtTextBox" runat="server" Width="217px" class="round default-width-input"
[code]....
I have a DetailsView on the page and I have made one of the fields a TemplateField. In the EditItemTemplate and InsertItemTemplate I have a DropdownList that is databound to a table in my Sql Server database. I wanted to add an initial value to the DropdownList
namely "- select -" .
I set the AppendDataBoundItems property to true and added the initial value as a ListItem.Markup of the DropdownList
<asp:DropDownList ID="DropDownList_HP" runat="server"
AppendDataBoundItems="True" DataSourceID="SqlDataSource_HP" [code]...
This works fine for new input. The problem is however that the database already has records that were entered through a Windows Application and many of these records has a null value in this field and exceptions are thrown when I tried to open these records
and the system tried to set the SelectedValue of the DropdownList.After some more searching I found this help
http://msdn.microsoft.com/en-us/library/ms366709.aspx
So I changed the ListItem in the DropDownList markup to the following:
<asp:DropDownList ID="DropDownList_RefHospDV4" runat="server"
AppendDataBoundItems="True" DataSourceID="SqlDataSource_RefHosp" [code]...
This now solved the problem of opening a record where the value is null in the database, BUT now the RequiredFieldValidator is not validating anymore to make sure that a databound item is selected for this field and not the initial value "- select -". So basically now it is not checking anymore to see if valid input has been entered for the DropDownList and it accepts "- select -" thus it acts as if the field is not a required field anymore.
In short what is required is that I want to make sure that the user enters a valid selection in the DropDownList, but it must also cater for old records that do not have this field entered yet so that those old records can be opened in the DetailsView .Opening Old records (with null in that field):When these old records are opened in the DetailsView the DropDownlist should show "- select -" when the value in the database is null.
Saving records (old or new records):When saving the record in Insert mode or Update mode the RequiredFieldValidator should show that a valid input is not selected if the DropDownList is still on "- select -".
I have a aspx page with a ascx control inside an ascx control and the required field validator is not hit on the action of the page.
The issue is with the 2nd nested ascx control. The field validators in the first ascx control validate correctly, but with the ascx control inside the ascx control there are issues.
The nested ascx control is a repeater control and this may be the reason, but I am unsure.
I'm not exactly sure what question to ask, but I'll list a few below.
How do I attach the field validators up a level to the 1st ascx control?
Is it possible to put required fields into a nested ascx control?
I have a custom control that has a hidden field. Upon postback I want to obtain the value stored in it, but it's always an empty string.I am performing client-side manipulation of the hidden field values and have verified in firebug that the fields are correct before issue a post back,Here is the setup:
public class DualListPanel : SWebControl, INamingContainer
{
protected IList<DlpItem> UnassignedList { get; set; }
protected IList<DlpItem> AssignedList { get; set; } [code].....
Is it possible to have "Required Field Validator" controls to validate more than one field (example I have 12 textboxes that are required. I want to try an avoid having 12 RFV controls. If a validation does get triggered, is there a way to display a customized message ("textA is empty" or "textB is empty") etc.?
View 4 RepliesI have a parent control that has an instance of a HiddenField child control. I am using CreateChildControls() to add it. Everything works client side including the values being added to the field. However, on postback, the reference to the field is null
here is the code
[code]....
I have tried simply relying on the ViewState ... then also attempted using FindControl(). Neither works, it comes up as a null reference ... any input on what is going here?
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"........
I found a very piculiar care in ASP.Net MVC webpage submission to server. The model object is bound to the action event. It was working fine. I added another interger field to my model object and added a control to the webpage(.aspx). When I submit the page without entering data in the new field, I found that my ModelState.IsValid in the Action Event, is false and there is error registered as the field value is required. I am surprised why it will be a mandatory field? when I have not set is as Mandatory ? Is there some thing wrong I am doing? I putting the samples below.
New Filed in ASPX:
[Code]....
Controller Object :
[
{
AcceptVerbs(HttpVerbs.Post)]public
ActionResult AddDriver(Driver driver)
}
On submit of the page when control comes to the AddDriver Action event , I found the ModelState.IsValid is false.
why it is happening as I have not put any require attribute in the Model object's field.
I have this in my Model
[Code]....
When on the view the validation doesnt fire stating that it is required - where as the other values do (such as strings or integer fields )- how does this work for Booleans?
Page validation using Required field validator is not firing I configured everything and tested in other page and found its working fine.
I placed my controls under TabContainer is that the reason for not firing.
I'm trying to write a form for a user to leave a testimonial on the website. I would like a group of inputs related to the users name (title, firstname and surname) or an input for their company name to be required. They can leave both if they like, but they must at least either fill in all the inputs related to their name or the input for their company name.can I do this with the RequiredFieldValidator?
View 3 RepliesI've currently got a RequiredFieldValidator added to the top 3 fields of each generated set of questions. The questions are dynamic, and what I'd love to do is pop up a red "YOU MISSED SOME FIELDS...blah blah" msg above the Submit button when the user misses those top fields. (I did do this previously with a custom validator, but I've had trouble doing this w/the dynamic fields that I've created.)Right now, if you miss a top-3 field, the page just does nothing, and the user has to manually scroll up to the top of the page to see "required field" pop up in red next to the missed field.
View 3 RepliesI have the need to remove my custom field validators on the clientside based on certain conditions
View 1 Replies