.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Sharon Maxwell
Post New Web Links

Validating ICollection using DataAnnotations

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :ASP.Net
 
 What's the best way to validate ICollectionie. sample class: public class BlogPost    {        public BlogPost()        {            this.CreateDate = DateTime.Now;            this.IsPostNow = false;        }        public virtual int BlogPostId { get; set; }        public virtual int AdminId { get; set; }        public virtual ICollection<BlogCategory> BlogCategory { get; set; }    }what's the best way to ensure that at least ONE BlogCategory is selected (if on the edit page BlogCategory is a list of checkboxes)thanks


View Complete Post


More Related Resource Links

LINQ to SQL - Validating if item is in Database, but if item is not items not inserting into databas

  

Hello,

I am new to this, so bear with me.  I am writing an application in C# that uses LINQ to validate a datacontext off a textbox to see if the record exists already.  If the record does exist I inserted an if statement to advise the user that the record exists, if the record does not exist I would like to allow the record to be added to the database.  If I take out my else statement everything works fine as far as inserting goes, but I do not want to allow inserts in this scenario.  I have tried moving the if and else statement to different parts of the code but can't quite figure this one out.  Any help would be apprecaited, attached is the code.  This code is set to a button press.  As a matter of fact, if you see any other errors along the way please feel free to point them out. 

Thanks,

Pete

    protected void enterBTN_Click(object sender, EventArgs e)
    {
        //make new data context

        SHCDataContext insNewAll = new SHCDataContext();
 
        //LINQ to check if customer exists in database
        var checkExisting = from c in insNewAll.Customers
                            where c.custLastName.Contains(custLastNameTB.Text.ToString())
                            select c.custLastName;
        //make list to store values
        L

Regex pattern for validating IPv6

  

Can anyone can make a regular expression pattern for validating IPv6 (not IPv4)?

Ipv6 has many formats and aliases. I tried making the pattern but written in a lot of codes (i'm not sure my code below will be 100% accepting valid formats and 100% declines invalid formats).

(([0-9a-fA-F]{1,4}:){1,1}(:[0-9a-fA-F]{1,4}){1,6})
|
(([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5})
|
(([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4})
|
(([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3})
|
(([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2})
|
(([0-9a-fA-F]{1,4}:){1,6}(:[0-9a-fA-F]{1,4}){1,1})
|
((([0-9a-fA-F]{1,4}:){1,7}|:):)
|
(:(:[0-9a-fA-F]{1,4}){1,7})
|
(((([0-9a-fA-F]{1,4}:){6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}))
|
((([0-9a-fA-F]{1,4}:){5}[0-9a-fA-F]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}))
|
(([0-9a-fA-F]{1,4}:){5}:[0-9a-fA-F]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9a-fA-F]{1,4}:){1,1}(:[0-9a-fA-F]{1,4}){1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,3}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,2}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9

Which ComponentModel.DataAnnotations attributes are used in the Dynamic Data metadata classes?

  

This namespace contains a lot of attributes for use in, I'm sure, many different applications. I'm curious to know which subset of the attributes in this namespace can be and are used in the Dynamic Data proxy class system, where the entity class is given an attribute that specifies a metadata type. That type contains properties with the same names as properties in the entity class, and the metadata provider builds MetaColumns using attributes on properties in these 'buddy' (proxy') classes.

So far my list includes, from System.ComponentModel.DataAnnotations:

Required, Range, DisplayFormat, StringLength, UIHint, DataType, Regular Expression, Display Column, Editable, and CustomValidation.

And from System.ComponentModel:

DisplayName, Description, and DefaultValue.

Am I missing any?


This was originally asked by myself on StackOverflow at: http://stackoverflow.com/questions/3537356/which-componentmodel-dataannotations-attributes-are-used-in-the-dynamic-data-meta


css validating error

  

I'm having lots of errors with my page because of the css validating erros that i am getting when i debug the page, my page linked to a css stylesheet,

could you please help me remove these errors?


page markup :


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ma.aspx.vb" Inherits="ma" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<h

Need help with validating an alphanumeric string within a textbox control.

  
Hi everyone,I am developing a simple WinForms app for a presentation next week and need to validate that a particular string in a particular textbox is alphanumeric.  I have included the code from the button click event handler below: // Alphanumeric private void btnValidate4_Click(object sender, EventArgs e) { try { if (txtAlphanumeric.Text == "") MessageBox.Show("Please enter an alphanumeric string before clicking the 'Validate' button.", "Whoa there, pardner!!", MessageBoxButtons.OK, MessageBoxIcon.Information); else { Regex rgxAlphanumeric = new Regex("^[a-zA-Z0-9]*$"); Match alphaNumericMatch = rgxAlphanumeric.Match(txtAlphanumeric.Text); if (!alphaNumericMatch.Success) MessageBox.Show("The string supplied does NOT match the specified pattern.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); else { MessageBox.Show("The supplied string matches the specified pattern.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

DataAnnotations.Display.Order not working with MVC 2 (using Futures)

  
Hi All!I have these two classes in my model: public partial class Customer { #region Primitive Properties [Display(Name="Note", Order=10)] public virtual string Notes { get; set; } ... public partial class AdvisoryCentre : Customer { #region Primitive Properties [Display(Name="Denominazione", Order=-10)] public virtual string BusinessName { get; set; } ... In the editor for the AdvisoryCentre model, using Html.EditorForModel, the behavior is not what i expected. When creating a new AdvisoryCentre object, BusinessName and Notes fields are shown in correct order, but when i edit an existing AdvisoryCentre with empty Notes property, the Notes field is always shown before BusinessName field. If Notes property is not empty, the fields order is correct.There is a workaround for this problem?Thankyou

Validating Custom Types and Html.EditorFor() Templates?

  
I'm finding my self with the problem that if I do not show the Template for a "complex" object I have in the main view object I still get the errors in the summary. How do i get around this? I've got a model with say:   HouseType ->Persons (has its own editor template) ->Pets(has its own editor template)   In the create view I show each one depending if they are not null. But when I try to validate HouseType and say I have Persons not null and pets is null. I get errors of validation for pets. How do I get around this? -Thanks

Validating Employee ID With SQL Server

  
Hello everybody.I am designing a validation form which has a textfiled for inserting Employee ID and a submit button for parsing inserted value. On clicking that button the SubmitButton_Click() validate the inserted value against SQL Server database. The database has a table name EMPLOYEE containing ID and Name of employees. Now I have designed the .aspx page but stuck in the rest of the job. If any one please tell me how can I do it, it will be very helpful to me.Thank you.

Validating Textbox for Numeric Values

  
I want to validate a textbox that only a numeric currency value can be put into it, for example 0.00. I thought the following code was correct but it doesnt seem to wrk, its causing an error on my page and when I remove it the page is fine, it doesn't actually give exact details of the error on the page just says "syntax error" in the browser that is all.<asp:CustomValidator runat="server" ErrorMessage="Please enter a numeric value for Night Rate in the format of 0.00" ID="NightRateNum" ControlToValidate="txtNightRate" Text="*" ClientValidationFunction="^\d+(\.\d\d)?$"></asp:CustomValidator>Would appreciate if any can tell me where I went wrong Thanks

DropDownList Validators Not Validating

  
I can't seem to get any sort of validator to fire when validating my DropDownList.  I just want to make sure that it isn't left at "--Select--" when the user presses the Add button on the page.  I've tried a range validator and required field validator and neither seem to fire at all.  My DropDownList contains ID which is an int that is hidden and Name which is a string that is displayed.  The ID is -1 for "--Select--".I use these all the time and can't understand why the page in this new solution is any different from other solutions I have done in the past.  What have I missed?<asp:DropDownList ID="drpProducts" runat="server" CausesValidation="True" ValidationGroup="AddExistingProduct"></asp:DropDownList> <asp:Button ID="btnAddExistingProduct" runat="server" Text="Add" onclick="btnAddExistingProduct_Click" ValidationGroup="AddExistingProduct" CausesValidation="true" /> <asp:RequiredFieldValidator ID="rfvAddExistingProduct" runat="server" Enabled="true" ValidationGroup="AddExistingProduct" ControlToValidate="drpProducts" InitialValue="-1" ErrorMessage="*"></asp:RequiredFieldValidator> <asp:RangeValidator ID="

Validating DropdownList Inside Gridview Using Javascript

  
hi All,      I have Gridview with Dropdownlist which contains data as {select,1,2,3} .Gridview contains multiple rows of data.Submit button is also on form but outside gridview. If any of the rows of gridview dropdownlist contain value as "Select" and click Submit button ,give message as "Please select value". I want to do this stuff using javascript. Thanks in advance.

Validating cluster resource: SQL Server and SQL Server Agent services

  
SQL Server 2008 R2 installed on a Windows Server 2008 R2 2-node cluster. Cluster validation wizard warns for SQL Server and SQL Server Agent services: This resource is configured to run in a separate monitor. By default, resources are configured to run in a shared monitor. This setting can be changed manually to keep it from affecting or being affected by other resources. It can also be set automatically by the failover cluster. If a resource fails it will be restarted in a separate monitor to try to reduce the impact on other resources if it fails again. This value can be changed by opening the resource properties and selecting the 'Advanced Policies' tab. There is a check-box 'run this resource in a separate Resource Monitor'. "Should" SQL Server and SQL Server Agent services run in shared (default) or separate monitors in this environment?

Validating cluster resource: SQL Server and SQL Server Agent services

  
SQL Server 2008 R2 installed on a Windows Server 2008 R2 2-node cluster. Cluster validation wizard warns for SQL Server and SQL Server Agent services: This resource is configured to run in a separate monitor. By default, resources are configured to run in a shared monitor. This setting can be changed manually to keep it from affecting or being affected by other resources. It can also be set automatically by the failover cluster. If a resource fails it will be restarted in a separate monitor to try to reduce the impact on other resources if it fails again. This value can be changed by opening the resource properties and selecting the 'Advanced Policies' tab. There is a check-box 'run this resource in a separate Resource Monitor'. "Should" SQL Server and SQL Server Agent services run in shared (default) or separate monitors in this environment?

MVC is validating primary key which is identity

  
Hello,   I am following this tutorial : http://www.asp.net/mvc/tutorials/getting-started-with-mvc-part4 I am where you "Create" an entry  in the table, i have deleted the Id field, as Id is my primary key, and Is Identity = Yes, Identity Increment = 1, Identity Seed = 1. When i hit the create button, the Id value is being validated, giving an invalid error. If i add the Id column back to the page, and fill in any number and click create, the entry is added to the database, with the Id value incremented (the typed in value does not matter). I believe this must have to do with the Movies.Designer.cs... but not sure how to fix it. Id should not be validated as it auto-incraments, but the model is looking for a Id value.... How do i fix this?   Thanks, -Mike

DataGrid DataAnnotations DisplayAttribute

  

Does the data annotations display attribute work with the WPF data grid?  I have tried it and it seems to be ignored.  Is there something special that has to be done to make it work?  They do work fine if I create a Silverlight application are they only for Silverlight?  I am using Visual Studio 2010 and .Net 4.  I'm posting here as searching on data annotations seems to lead to silverlight related pages rather than WPF related.  Thanks.

 


validating radiobuttonlist inside gridview

  

I am sure this has been asked before but I cannot find a solution to my problem. I have a radiobuttonlist inside an itemtemplate inside my gridview. It contains a list of items with yes or no options. What I need to do is make sure all items were selected either 'Yes' or 'No' when I click a button. If some our left blank I want to stop them from proceeding and give them a message that not all questions are answered. Any ideas about how I could go about this or a different way that would be easier.

<asp:GridView ID="GridView1" CssClass="tabletext" Width
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend