Invoking a data form action from within the UI model code.

I have the following action in my data form:

//
//_filecontactreport
//
_filecontactreport.Name = "FILECONTACTREPORT";
_filecontactreport.Caption = "File contact report";
_filecontactreport.DataFormInstanceId = new System.Guid("8f5cdf69-8f03-4d3c-b6b5-3f5d29e2fce8");
_filecontactreport.RecordIdDefinition = "Fields!STEPID";
_stepid.LinkedActions.Add(_filecontactreport);
this.Actions.Add(_filecontactreport);

I want to invoke this action when a field is populated instead of waiting for the user to click the action button. I am not sure how to do this. Here is what I've tried unsuccessfully. I'm not sure what the invoke args are supposed to be. This code does not error. It just does nothing.

//invoking this does not seem to work
InvokeFormActionArgs invokeargs = new InvokeFormActionArgs();
System.Collections.Specialized.NameValueCollection parameters = new System.Collections.Specialized.NameValueCollection();
invokeargs.Cancel = true;
invokeargs.Model = _model;
invokeargs.Parameters = parameters;
_filecontactreport.Invoke(invokeargs);

Anyone have any ideas?

Comments

  • Hey Harry,

    It sounds like you'll want to create an event listener for the value being changed. You can do this easily by specifying what you want to happen in the OnCreated() method that gets generated automatically when you create a UI Model, similar to the example below:

    partial void OnCreated()

    {

    this.Loaded += YourUIModel_Loaded;

    this.SOMEVALUE.ValueChanged += SOMEVALUE_InvokeAction;

    }

    The this.Loaded line is auto generated so don't worry about that but when you get to the += of the second line Visual Studio will prompt you to hit tab twice to auto generate the method for the event listener that you're trying to set up (that is if you're typing it out). Once you have your method you can specify inside of it what it does.

    One thing to keep in mind is you'll probably want to change it so that when the focus changes from that box and the value is changed that it executes what you want (otherwise any time you type in an extra character it'll run the action)

    Does this make sense?

  • Hey Steven,

    Thanks for the response. Yep, I know how to do the event listener part. I'm trying to figure out how to call the action once I'm in the handler.

  • If you already have the event handler set up I would just include the Blackbaud.AppFx.Server package into your project and just call the dataform or other component you're trying to call inside of the event handler method that gets generated. Unfortunately this won't cause the dataform to appear so if that's what you're going for I've not had any experience with that.

    This might help you if you're trying to get a dataform to pop up instead.