locked
ValidateRequest False - Now how do I send validation messages manually RRS feed

  • Question

  • User-1254308814 posted

     

    I think the title says it all. I am in my insert mode and I have to let admin users update htmlcode into the database from the managment console(my dynamic data site application). Once ValidateRequest is set to false all the default validation is gone. How do I push validation messages to the ui. I also don't know where to put in this validation without basterdizing the architecture. When I go to list view I notice that my partial On.... validation methods are getting raised(probably by design). I can't go into my database to check if the user exists for my insert for that reason and the fact that updates would require that the user always changes his/her name.  Any advice on this sort of manual validation?

     Can I access the validator, cancel ,and show the  message from the datasource oninserting event? I will look at that next.

    Friday, October 24, 2008 3:46 PM

All replies

  • User2130758966 posted

     Hey, you can create the standard asp validation controls and invoke them programatically by using the .Validate() function.

     Check this out for a run down:

    Friday, October 24, 2008 5:59 PM
  • User-330204900 posted

    Can I access the validator, cancel ,and show the  message from the datasource oninserting event? I will look at that next.

    I would certainly look into the OnIserting event, in Linq to SQL I have used this to validate uniquness and also the add user info automatically to the record.

    see DynamicData - Limit Data Displayed By User and 

    //Business Logic example
    public partial class NorthwindDataContext : System.Data.Linq.DataContext
    {
    	partial void InsertCustomer(Customer instance)
    	{
    		var NWDC = new NorthwindDataContext();
    		if (NWDC.Customers.SingleOrDefault(c => c.CustomerID == instance.CustomerID) != null)
    		{
    			throw new ValidationException("Duplicate CustoemrID is not allowed");
    		}
    		else
    		{
    			// finally send this to the DB
    			this.ExecuteDynamicInsert(instance);
    		}
    	}
    }

    This works for Linq to SQL, I've not mastered Linq to Entity Framework as yet [:(]

    Hope this helps [:D]

    Friday, October 24, 2008 8:04 PM
  • User-1254308814 posted

    It made more sense to transfer this to a properly labeled post rather than be confusing.

    Html Content Input for Insert/Edit CustomPages

    Saturday, October 25, 2008 5:32 AM
  • User-1254308814 posted

    It made more sense to transfer this to a properly labeled post rather than be confusing CONT...

    Saturday, October 25, 2008 12:44 PM
  • User2130758966 posted

    Can I access the validator, cancel ,and show the  message from the datasource oninserting event? I will look at that next.

    I would certainly look into the OnIserting event, in Linq to SQL I have used this to validate uniquness and also the add user info automatically to the record.

    see DynamicData - Limit Data Displayed By User and 

    //Business Logic example
    public partial class NorthwindDataContext : System.Data.Linq.DataContext
    {
    	partial void InsertCustomer(Customer instance)
    	{
    		var NWDC = new NorthwindDataContext();
    		if (NWDC.Customers.SingleOrDefault(c => c.CustomerID == instance.CustomerID) != null)
    		{
    			throw new ValidationException("Duplicate CustoemrID is not allowed");
    		}
    		else
    		{
    			// finally send this to the DB
    			this.ExecuteDynamicInsert(instance);
    		}
    	}
    }

    This works for Linq to SQL, I've not mastered Linq to Entity Framework as yet Sad

    Hope this helps Big Smile

     

     

    Thanks for posting this example! Its not my thread but when I saw your code example I looked up SingleOrDefault because I didnt think your null check was correct. I thought it returned an instance of TSource but with all empty / min values.

    This has educated me [:)]

    Ref for the curious:

    Saturday, October 25, 2008 2:41 PM
  • User-330204900 posted

    Thanks for posting this example! Its not my thread but when I saw your code example I looked up SingleOrDefault because I didnt think your null check was correct. I thought it returned an instance of TSource but with all empty / min values.

    This has educated me Smile

    It took me some time to work it out [:$]

    Thanks [:D]

    Saturday, October 25, 2008 5:06 PM
  • User-1254308814 posted

    It turns out I am not using the LINQ for my application.  It might be a little overkill to generate a LINQ datalayer for a user check. Using a typed dataset for that user check might be ok.

    Boolean ? nameExists = false;
    QueryAdapter query = new QueryAdapter();
    query.CheckNameExists(name, out nameExists);

    Since I have a nettiers datalayer setup for my application I could do this.
    DataRepository.PeopleProvider.CheckNameExists(name, out nameExists);

    Setting up the user control was really the answer to my problem and it should be noted that I terribly mislabelled the Title of this post. That was mainly because I was barking up the wrong tree and trying to solve related problems rather than the real problem. That being, the ability to update html content and keep the regular validations going as they previously worked(ie. setup through metadata in related metadata classes).

    Saturday, October 25, 2008 6:12 PM
  • User-330204900 posted

    Ah! so that means your not using DynamicData at all?

    Sunday, October 26, 2008 4:53 AM
  • User-1254308814 posted

    Yes, I am using Dynamic Data. I am using ADO.NET Entities framework style. I really like LINQ but I had gotten off and running with the ADO.NET Entities, so I am sticking with them for the rest of this project. If there is a good way to hook up regular stored procedures with the ADO.NET entities I am all ears but it doesn't seem clear to me at the moment.

    Sunday, October 26, 2008 5:21 AM
  • User-330204900 posted

    I'm not sure this is what you want but MSDN has this regarding sprocs in EF Stored Procedure Support (Entity Framework)

    Sunday, October 26, 2008 5:46 AM
  • User-1254308814 posted

    Hey thanks, I will look it over in the morning.

    Sunday, October 26, 2008 6:05 AM
  • User-330204900 posted

    Hi Jwise I'l working my way through learning Linq to Entity Framework and will  post some examples of doing the Business Logic example when I get that far, I just wish it was as intuative as L2S was [:(]

    Sunday, October 26, 2008 12:21 PM