CSLA SilverLight

CSLA SilverLight

Old forum URL: forums.lhotka.net/forums/t/7699.aspx


SouthSpawn posted on Tuesday, September 29, 2009

A few questions here.
 
  1. If I am using the CSLA:InvokeMethod to save my data using the dataprovide inside my XAML. What if I want a popup message box to display "After" the save has been completed.
    I am not sure how do I go about doing this using the data provider.
  2. I have a Telerik Combobox on the page, for some reason it's not databinding at all using the dataprovide. But when I manually do it in the code behind it works no problem.
  3. What is the best way to save data on my SilverLight Application "if" I have a "hybrid" data form with SilverLight textbox fields as will as standard asp.net textbox fields?
  4. I don't care for CSLA automatically disabling the buttons for me. If requires the user to change the data first, which I have no problem with. BUT, the user will then have to click on the "Tab" button in order for the button to become enabled.

    Me personally, I don't use the keyboard that much, I use the mouse button.
    So the current way it works, if I make a change to my form, then I try to use my mouse button to save my new changes. The button will not become enabled until I press the tab key.
    There are situations where I might just change "one" field, then directly attempt to save the data using my mouse instead.

    I have tried doing the ManualControl for the button inside my XAML, and it still disables the control. Any thoughts????
Any code examples someone can share.

Thanks

RockfordLhotka replied on Tuesday, September 29, 2009

SouthSpawn:

If I am using the CSLA:InvokeMethod to save my data using the dataprovide inside my XAML. What if I want a popup message box to display "After" the save has been completed.
I am not sure how do I go about doing this using the data provider.

The data provider is designed to support a simple CRUD screen and is modeled closely after the WPF data provider model. If you want more control over the process, you'll need to use code-behind or the MVVM pattern.

SouthSpawn:

I have tried doing the ManualControl for the button inside my XAML, and it still disables the control. Any thoughts????

That sounds like a bug. If you tell InvokeMethod to allow manual control over the UI visual state it shouldn't alter that control's state.

Can you (or anyone else) confirm that this bug exists?

SouthSpawn replied on Tuesday, September 29, 2009

Rocky,

Now when i complile I am getting.
 
csla:InvokeMethod.ManualEnableControl="true"
 
Error 5 The property 'ManualEnableControl' does not exist on the type 'Button' in the XML
 
Here is my button code.
 
 <Button
                    x:Name="UpdateCompanyButton"
                    Content="Update Company" 
                    csla:InvokeMethod.ManualEnableControl="true"
                    csla:InvokeMethod.TriggerEvent="Click"
                    csla:InvokeMethod.Resource="{StaticResource CompanyData}"
                    csla:InvokeMethod.MethodName="Save" ></Button>

RockfordLhotka replied on Tuesday, September 29, 2009

I don’t know – that code looks right to me. Does ManualEnableControl appear in intellisense?

 

pondosinat replied on Tuesday, September 29, 2009

I just tried setting ManualEnableControl in xaml and got the same error. It shows up in intellisense, just doesn't compile. It looks like a bug, though I can't find the source of the bug in the CSLA code.

As a work around, you can set this flag programmatically in the meantime (which does compile):

Csla.Silverlight.InvokeMethod.SetManualEnableControl(buttonControl, true);

RockfordLhotka replied on Tuesday, September 29, 2009

What version of CSLA .NET are you using?

pondosinat replied on Tuesday, September 29, 2009

I'm using 3.7.1.0

RockfordLhotka replied on Tuesday, September 29, 2009

Try replacing the ManualEnableControl property declaration code (static field and two methods) with the following code (from version 3.8):

    /// <summary>
    /// Value indicating whether the UI control should be
    /// manually enabled/disabled.
    /// </summary>
    public static readonly DependencyProperty ManualEnableControlProperty =
      DependencyProperty.RegisterAttached("ManualEnableControl",
      typeof(bool),
      typeof(InvokeMethod),
      new PropertyMetadata((o, e) =>
      {
        var ctrl = o as UIElement;
        if (ctrl != null)
          new InvokeMethod(ctrl);
      }));

    /// <summary>
    /// Sets the value indicating whether the UI control should be
    /// manually enabled/disabled.
    /// </summary>
    /// <param name="ctrl">Attached control</param>
    /// <param name="value">New value</param>
    public static void SetManualEnableControl(UIElement ctrl, bool value)
    {
      ctrl.SetValue(ManualEnableControlProperty, value);
    }

    /// <summary>
    /// Gets the value indicating whether the UI control should be
    /// manually enabled/disabled.
    /// </summary>
    /// <param name="ctrl">Attached control</param>
    public static bool GetManualEnableControl(UIElement ctrl)
    {
      return (bool)ctrl.GetValue(ManualEnableControlProperty);
    }

I don't remember exactly why, but when I was rebuilding this control for 3.8 I know I reworked the way the attached properties are declared, and this one did give me some trouble. It works in 3.8 though, so I suspect swapping out this code may solve the issue.

SouthSpawn replied on Wednesday, September 30, 2009

Rocky,

Any suggestions on how I can do a "MessageBox.Show("Company has been updated successfully!!!")
 
After the DataProvider is finished with the update?
I don't see an event anywhere.

What am I overlooking?
 
Also What is the best way to save data on my SilverLight Application "if" I have a "hybrid" data form with SilverLight textbox fields as will as standard asp.net textbox fields?

Should I just get the DataProvider object from the resources collection and manually call the save there?

sergeyb replied on Wednesday, September 30, 2009

Provider in SL has Saved event you can use.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: SouthSpawn [mailto:cslanet@lhotka.net]
Sent: Wednesday, September 30, 2009 11:10 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] CSLA SilverLight

 

Rocky,


Any suggestions on how I can do a "MessageBox.Show("Company has been updated successfully!!!")

 

After the DataProvider is finished with the update?
I don't see an event anywhere.


What am I overlooking?

 

Also What is the best way to save data on my SilverLight Application "if" I have a "hybrid" data form with SilverLight textbox fields as will as standard asp.net textbox fields?

Should I just get the DataProvider object from the resources collection and manually call the save there?



SouthSpawn replied on Wednesday, September 30, 2009

Sergeyb,
 
Thanks for the response.

My last question is, how to I manually save data to the dataprovider?

In my situation, I need to use a "ScriptableMember" method to grab some data from one of the "Html" controls on the page.
 
I am trying to do something alone the lines of. (This is just an example)
 
private string _s;
 
private void UpdateCompany_Button_Click(object sender, RoutedEventArgs e)
{
   p = (Csla.Silverlight.CslaDataProvider)this.Resources["CompanyDataProvider"];
 
   SetSummaryFromDOM();
 
   Company c = (Company)p.Data;
 
   c.Description = _s;
 
  //I am lost on what to do next.
  //Since p.Data is readonly, I cannot update the object manually by just doing a
  
  //p.Data = c;
  //p.Save();
 
}
 
private void SetSummaryFromDOM()
{
      ScriptObject so = (ScriptObject)HtmlPage.Window.GetProperty("GetDescriptionContent")
 
      //This will call a javascript function, that will grab the content out of an html control.
      //Then it will call the SilverLight's "Summary" method to pass that data back to the SL App.
      so.InvokeSelf();
}
 
[ScriptableMember]
public void Summary(string s)
{
      _s = s
}

sergeyb replied on Wednesday, September 30, 2009

This should work

 

private void UpdateCompany_Button_Click(object sender, RoutedEventArgs e)

{
   p = (Csla.Silverlight.CslaDataProvider)this.Resources["CompanyDataProvider"];

 

   SetSummaryFromDOM();

 

   Company c = (Company)p.Data;

 

   c.Description = _s;

 

 

Additional code: -

p.Saved+=(o, e)=>

{

            If (e.Error == Null)

                        MessageBox.Show(“Success”);

            Else

            {

                        Messagebo.show (“Error: “ + e.Error.Message);

}

// hide busy animation unless bound to provider

};

// Show some busy animation unless bound to provider

p.Save();

 

You would need to plug in your own error handler, messageboxes are there as an example what to listen to.

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: SouthSpawn [mailto:cslanet@lhotka.net]
Sent: Wednesday, September 30, 2009 11:53 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: CSLA SilverLight

 

Sergeyb,

 

Thanks for the response.

My last question is, how to I manually save data to the dataprovider?

In my situation, I need to use a "ScriptableMember" method to grab some data from one of the "Html" controls on the page.

 

I am trying to do something alone the lines of. (This is just an example)

 

private string _s;

 

private void UpdateCompany_Button_Click(object sender, RoutedEventArgs e)

{
   p = (Csla.Silverlight.CslaDataProvider)this.Resources["CompanyDataProvider"];

 

   SetSummaryFromDOM();

 

   Company c = (Company)p.Data;

 

   c.Description = _s;

 

  //I am lost on what to do next.
  //Since p.Data is readonly, I cannot update the object manually by just doing a

  

  //p.Data = c;

  //p.Save();
 
}

 

private void SetSummaryFromDOM()
{
      ScriptObject so = (ScriptObject)HtmlPage.Window.GetProperty("GetDescriptionContent")

 

      //This will call a javascript function, that will grab the content out of an html control.

      //Then it will call the SilverLight's "Summary" method to pass that data back to the SL App.

      so.InvokeSelf();
}

 

[ScriptableMember]

public void Summary(string s)
{
      _s = s
}



SouthSpawn replied on Wednesday, September 30, 2009

This is great.

Thanks ALOT!!!

Copyright (c) Marimer LLC