Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling Validation when leaving controls in web form
Message
De
07/09/2010 15:22:45
 
 
À
07/09/2010 14:14:27
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01479579
Message ID:
01480447
Vues:
44
>>>>I am wanting to call my Business Rules when I leave a control on a web form. I've found an example in the help for winforms, is there a similar example for web forms as I am so far not having success in adapting the sample.
>>>Have you tried executing the form's Save method? I'm not using web forms but it seems like that might accomplish what you need.
>>
>>Hi Linda,
>>
>>I don't want to save the data at this point in time. I just want to do the validation at the point where the user enters data in a particular field as well as at the point where the data gets saved.
>
>
>Frank,
>
>You can call your business rules yourself anytime you want to. You may want to consider however that with a web form this may cause a post back each time. You will need to trigger a post back and then you can get to your rules object via the business object and you can call the validation methods you have there individually. Is your plan to check the rule for each control as they leave it? What will you do if the rule is broken?
>
>Tim

Hi Tim,

are you back from your vacation?

Yes, I want to validate certain fields/controls as the user enters data in them.

I have tried this:
        protected void txtRiderSumAssured_TextChanged(object sender, EventArgs e)
        {
            TextBox thisTextBox = (TextBox)sender;
            this.oPolicyRider.Rules.ClearAll();
            GridViewRow gvr = (GridViewRow)thisTextBox.Parent.Parent;
            if (this.oPolicyRider.Rules.ValidateSumAssuredMaxMin((Guid)this.oPolicyRider.DataSet.Tables[0].Rows[gvr.RowIndex]["RiderFK"], decimal.Parse(thisTextBox.Text)) != null)
            {
                // show the message somehow
            }

            this.CalculateRiderPremium(true, gvr);
            this.SetFocus(gvr.Cells[3].Controls[1]);
        }
but I get an error:
Server Error in '/' Application.
Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

Line 37:                 {
Line 38:                     message = "Rider Sum Assured must be between " + oPlan.Entity.MinSumAssured.ToString() + " and " + oPlan.Entity.MaxSumAssured.ToString();
Line 39:                     this.AddErrorProviderBrokenRule("SumAssured", message);
Line 40:                 }
Line 41:             return message;


Source File: C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Business\PolicyRider\PolicyRiderRules.Partial.cs    Line: 39 

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   OakLeaf.MM.Main.Web.UI.mmWebDataHelper.SetControlErrorMessage(ImmWebBindingDataGrid control, mmBaseBusinessObject bizObj, mmBusinessStateChangeEventArgs e) +273
   OakLeaf.MM.Main.Web.UI.WebControls.mmGridView.StateChangeHandler(mmBaseBusinessObject bizObj, mmBusinessStateChangeEventArgs e) +211
   OakLeaf.MM.Main.Business.mmBusinessStateChangeDelegate.Invoke(mmBaseBusinessObject bizObj, mmBusinessStateChangeEventArgs e) +0
   OakLeaf.MM.Main.Business.mmBusinessObject.OnStateChange(mmBusinessState bizState, String tableName, Object primaryKeyValue, Object[] primaryKeyValues) +174
   OakLeaf.MM.Main.Business.mmBusinessObject.OnErrorProviderBrokenRuleAdd(mmErrorProviderArgs arg) +111
   OakLeaf.MM.Main.Business.mmBusinessRule.AddErrorProviderBrokenRule(mmErrorProviderArgs arg) +768
   OakLeaf.MM.Main.Business.mmBusinessRule.AddErrorProviderBrokenRule(String propertyName, String columnName, String errorText) +434
   OakLeaf.MM.Main.Business.mmBusinessRule.AddErrorProviderBrokenRule(String columnName, String errorText) +46
   SamaanSystems.IAS.Business.PolicyRiderRules.ValidateSumAssuredMaxMin(Nullable`1 planPK, Nullable`1 sumAssured) in C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Business\PolicyRider\PolicyRiderRules.Partial.cs:39
   SamaanSystems.IAS.Web.PolicyEdit.txtRiderSumAssured_TextChanged(Object sender, EventArgs e) in C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Web\PolicyEdit.aspx.cs:1244
   System.Web.UI.WebControls.TextBox.OnTextChanged(EventArgs e) +8739502
   System.Web.UI.WebControls.TextBox.RaisePostDataChangedEvent() +55
   System.Web.UI.WebControls.TextBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +10
   System.Web.UI.Page.RaiseChangedEvents() +165
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1485


Version Information: Microsoft .NET Framework Version:2.0.50727.3615; ASP.NET Version:2.0.50727.3614
Although VS debugger stops on this line:

if (BusinessObject.EntityFramework || (epArgs.TableName.ToLower() == TableName.ToLower()))

in OakLeaf.MM.Main.Web.UI.mmWebDataHelper.SetControlErrorMessage
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform