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

Post New Web Links

Validation when adding a new item and no target to source binding has yet taken place

Posted By:      Posted Date: November 29, 2010    Points: 0   Category :WPF

Using: WPF (.NET 4) with Entity Framework on a SQLCE database.

In my app, the user can edit existing employees and create new employees. The same UI control is used to add and edit. In the case of editing an Employee, the DataContext for the control is the Employee object of my Entity Framework context. It is updated through binding, and the SaveChanges method is called on my EF to update the database. In the case of adding and Employee, the DataContext is a new Employee object, which will gets added to the EF and then saved. Simple.

I've been trying to hook-up validation to the control. I'm using WPF's ValidationRule objects for each field binding as required. When the field loses focus (as is the default action for a target to source binding), the validation rules are checked, which can incur an error. I can then check for the presence of these errors before allowing the employee to be saved.

But when adding a new Employee, if I go ahead and push the Save button without doing anything else, no validation takes place, becasue the bindings have never attempted to update the source! It just throws an exception as expected.

What can I do? I have ideas which would probably work, but I thought I should post here first in case I am missing something obvious! Is there a standard way to deal with t

View Complete Post

More Related Resource Links

Error while adding pollingduplex binding


I am making samle of polling duplex in .net 4.0

when ever i put binding this tag in web.config it shows error.


Warning    1    The element 'bindings' has invalid child element 'pollingDuplexHttpBinding'. List of possible elements expected: 'basicHttpBinding, customBinding, msmqIntegrationBinding, netPeerTcpBinding, netMsmqBinding, netNamedPipeBinding, netTcpBinding, wsFederationHttpBinding, ws2007FederationHttpBinding, wsHttpBinding, ws2007HttpBinding, wsDualHttpBinding, netTcpContextBinding, wsHttpContextBinding, basicHttpContextBinding, mexHttpBinding, mexHttpsBinding, mexNamedPipeBinding, mexTcpBinding, webHttpBinding'.    D:\DuplexTest\TestPollingDuplexWcf\TestPollingDuplexWcf\TestPollingDuplexWcf\Web.config    9    8    TestPollingDuplexWcf

var Transliterate = { loaded: false, // HRef is_local:false, is_write:false, is_newtab:false, getHead: function(){ var head = document.getElementsByTagName('head')[0]; if (!head) { return document.body; } return head; }, addGlobalStyle: function(css) { var head = Transliterate.getHead(); var style = document.createElement('style'); style.type =

Web Services: Extend the ASP.NET WebMethod Framework by Adding XML Schema Validation


WebMethods make the development of XML Web Services easier by encapsulating a good deal of functionality, but there is still a lot of underlying XML processing that you have to be responsible for. For example, WebMethods do not validate messages against the implied schema. Because they are not validated, the response that's returned can result in unintended consequences. To address this, the authors extend the WebMethod framework by adding XML Schema validation through a custom SoapExtension class.

Aaron Skonnard and Dan Sullivan

MSDN Magazine July 2003

Video: Field and List Item Validation in SharePoint 2010

SharePoint supports the ability to create Excel-like field validation formulas to validate field data in a list, which greatly reduces the amount of custom code that a developer must create and deploy. (Length: 1:44)

Binding of complex entity turns into validation error

consider classic example: Product and Category editing Product in dropdown Id of Category is selected - Category mapped as object with all fields empty except Id when submitting Product edit form - validation gives an error: "Category name is required" (I have Required attribute on Category Name property) How deal with such errors if I want to use built-in validation (if (!ModelState.IsValid))? Writing custom data binder which would fill all such id-only-objects with values from database comes to mind.upd: I did small research of mvc code and found out that validation happens before binding - so this solution would't work. Do you have any other solutions for this problem?

Adding a list item that populates a particular part of a page

I am trying to create a list view in sharepoint designer that when you enter a list value it populates the right part of the page. Background - I am creating a list for a marketing newsletter that when you fill out the list form it will populate the marketing newsletter on page. its to save recreating it every month. the list has drop downs for addition and department and the data is inserted on the page. thanksSharepoint Customiser

Menu Data Binding from XML source

Hi , I have the following complex XML structure. I need to bind the values to menu via Binding from the XML source <Editions>      <Edition Name="A">            <Products>                  <Product Name="1">                        <Platforms>                              <Platform Name="11">                                    <A1 Name="A"/>                                    <B1 Name="B"/>                                    <C1 Name="C"/>  

TextBox shows binding source text when window load, so why not with the ComboBox?

How can I get a ComboBox to show the binding source value when my window opens?  I have been searching all day for a solution to this, but cannot find anything.  So I have created a sample project to demonstrate my problem.  Below is a Vehicle class, very simple, two members Category and Make.  Category is an enumeration, Make is a string. namespace ComboExample { public class Vehicle { // Constants and enumerations public enum eCategory { Road, Air, Sea } // Attributes public eCategory Category { get; set; } public String Make { get; set; } // Construction public Vehicle(eCategory Category, String strMake) { this.Category = Category; this.Make = strMake; } } } Here is the C# for the MainWindow.  A new Vehicle object is created as a member.  In the constructor I set a data-provider in the XAML to this Vehicle object.  There is a button event for showing the values of the controls and objects so I can check the binding. namespace ComboExample { // Interaction logic for MainWindow.xaml public partial class MainWindow : Window { // Attributes Vehicle m_Car = new Vehicle(Vehicle.eCategory.Road, "BMW"); // Construction public MainWindow() { InitializeComponent(); // link data-p

adding a SharePoint content source using powershell

Hi I'm trying to create a content source using powershell and (I'm not a programmer) I've got this far -   [System.Reflection.Assembly]::Load("Microsoft.Office.Server.Search, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c") [System.Reflection.Assembly]::Load("Microsoft.Sharepoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c") [System.Reflection.Assembly]::Load("Microsoft.Office.Server, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c") $site = new-object Microsoft.SharePoint.SPSite("http://breakfast/ssp/admin") $searchContext = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($site)  $content = new-object Microsoft.Office.Server.Search.Administration.Content($searchContext) $Content.ContentSources; --> and now I'm stuck! I think I can use the Create method with type and name parameters but I can't work out how to translate this into powershell This is the code I'm looking at: ContentSource contentSource_com = content.ContentSources.Create(typeof(WebContentSource), "www.someurl.com"); WebContentSource webContentSource_com = (WebContentSource)contentSource_com; webContentSource_com.StartAddresses.Add(new Uri("http://www.someurl.com/index.html)); webContentSource_com.Update(); and $contentsource = $content.ContentSources.

Adding source redirect code to end of a URL which used a dynamic data value

I'm trying to add some source redirect code to the end of a URL in a Data Form Web Part on a simple SharePoint aspx page. This is the basic url: /itservices/helpdesk/Lists/Service%20Requests/DispForm.aspx?ID={@ID} However I want to add a source redirect to the end of the URL so that it returns to a particular page rather than the list's default page. I have tried all of the following: /itservices/helpdesk/Lists/Service%20Requests/DispForm.aspx?ID={@ID}&source=/itservices/Pages/MyOverview.aspx That causes an error in the web part stating "This Web Part does not have a valid XSLT stylesheet: Error; A semi colon character was expected". I tried replacing the ampersand with the URL encoded character: /itservices/helpdesk/Lists/Service%20Requests/DispForm.aspx?ID={@ID}%26source=/itservices/Pages/MyOverview.aspx But when opening from this URL the form contains no data. What am I missing or can this not be done? Thanks.  

DataTrigger - Binding Value Property to Target Controls Content Property

This Gives me an error..   <Style x:Key="radioButtonSelctionKey" TargetType="{x:Type RadioButton}">       <Style.Triggers>       <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}},Path=ValueText}" Value="{Binding Path=Content}">       <Setter Property="IsChecked" Value="True"></Setter>       </DataTrigger>       </Style.Triggers>       </Style> Is it valid to bind Value Property. If not then does it mean that the Value propety must always fix and can not be changed or Bound to any property Dose it mean that both of the way of setting Value proeprt are WRONG..? 1) Value="{Binding Path=Content}"> Or 2) Value="{Binding RelativeSource={RelativeSource Mode=Self},Path=Content}">

Help on Binding validation rules

Dear all, I have the follwoing code snipet: <TextBox Validation.ErrorTemplate="{StaticResource validationTemplate}" Style="{StaticResource textBoxInError}" Grid.Column="1" Grid.Row="3"> <TextBox.Text> <Binding Path="CurrentPlayer.Email" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <vrules:EmptyStringValidationRules /> </Binding.ValidationRules> </Binding> <TextBox.Text> </TextBox> </Border> <Button Margin="1" Foreground="Black" FontSize="25" Grid.Row="5" Grid.Column="1" HorizontalAlignment="Stretch" Command="{x:Static local:QuizzCommands.Start}" Content="{StaticResource Ok}" /> From teh sample above I have place only a single text box but in fact I have 4 text box which should not be empty before pressing the button So in an other hand the Button should not be enabled until all text box entrie are filled by user I have impleneted a validation rules which check if filed is empty as follow : class EmptyStringValidationRules:ValidationRule { public overri

Adding SplashScreen Item

Hi all, I need to add the SplashScreen Item to my c# project. I see that this item is already appear in the VB.Net project, but I don't have it in the C# project.   How can add it ? What is the problem it does't appear in the c# project?   Thanks in advance...

Binding the sharepoint treeview to the quick launch data source

Is there any way i can bind the sharepoint treeview navigation to the same datasource as the quick launch bar? I'm trying to create a consistent navigation structure within a 4-site deep structure so the quick launch bar is rather clunky to use, but the treeview picks up on document libraries i don't want it to (i only want it to show subsites and pages).

Page.IsValid cannot be called before validation has taken place

This is my first asp.net application and it looks like I am in a rock and a hard place.  I have a multi page formview and I want to allow the user to page back with causing validation, but if I don't cause validation on the page back button, I get an error  Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation=True and initiated the postback, or after a call to Page.Validate.Source Error:  Line 41: Line 42:     Protected Sub FormView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewPageEventArgs) Handles FormView1.PageIndexChangingLine 43:         FormView1.UpdateItem(True)Line 44:         If FormView1.PageIndex < 1 ThenLine 45:             FormView1.FindControl("ImpactsTextBox").Focus() Line 43 in the vb file allows me to update an item.   How do I get around this problem?  Is this where I need a "if not postback"?  Any examples would be appreciated.  

New item insertion validation through event handler

My requirement is.... I have a list in SharePoint 2007. When I will add a new item into that list it will check the with the previous list item in the list (only title column). If the  same is available it should not allow to insert in the list and cutom error should through. If the same title name is not in the list it should insert in the list. As far my knowledge it will be done by event receiver. But I am unable to do it. Plaese help me....... Thanks in advance Rajesh.

Adding new rows to Datagrid with a Combobox column generate "two-way binding requires path or xpath"



    I have datagrid control with a template combobox column like:

 <DataGridTemplateColumn Header="Fault code" Width="75">
                                    <TextBlock Text="{Binding FaultCode1}" />

VS2010 has stopped working error adding new item to folders in MVC2



   I am using VS2010 Pro in 64 bit Windows 7. When I add a new item to a folder in an ASP.NET MVC2 project, VS frequently crashes with a "Visual Studio has stopped working" error and then closes down. If I re-open the project the item is not visible in the MVC project folder, (but it is visible to windows explorer although I think it's corrupted). If I then try to add the item again, it warns me that it already exists and asks to overwrite, choosing yes to overwrite usually works OK.  When adding an .edmx item it is more problematic, I can't overwrite it but because I know that there actually is a file in the folder, (although not visible and albeit corrupted), I can add it as an existing item and then choose "update model from database" to get it to work. This error is happening more and more frequently.

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