This is a migrated thread and some comments may be shown as answers.

setting the needle

11 Answers 112 Views
Gauge
This is a migrated thread and some comments may be shown as answers.
Harry
Top achievements
Rank 1
Harry asked on 03 Mar 2011, 09:48 PM
Hi all

We have a large asp.net web application that was not built as a silverlight application.  We recently found that we will need to add use a silverlight rad gauge to our existing application.  I can get the gauge into the page without a problem and set the needle to a number in the xaml.cs file but I cannot set the needle outside of the control due to the application is not originally a silverlight build.  It is not really an option to rebuild the application because of the man hours involved.  If any body has any ideas to get the info to the control We would be very thankful.

11 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 08 Mar 2011, 12:18 PM
Hi Harry,

You can pass parameters to the Silverlight control using the user-defined initialization parameters for Silverlight Plug-in Object. The sample code below passes the needle value to the Silverlight user control.
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
  <param name="initparams" value="needleValue=25"/>
  <param name="source" value="ClientBin/RadControlsSilverlightApp1.xap"/>
  <param name="onError" value="onSilverlightError" />
  <param name="background" value="white" />
  <param name="minRuntimeVersion" value="4.0.50826.0" />
  <param name="autoUpgrade" value="true" />
  <param name="onload" value="pluginLoaded" />
  <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
      <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
  </a>
</object>

<UserControl x:Class="RadControlsSilverlightApp1.MainPage"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <telerik:RadGauge Height="200" Width="200">
            <telerik:RadialGauge>
                <telerik:RadialScale>
                    <telerik:IndicatorList>
                        <telerik:Needle Name="Needle1" />
                    </telerik:IndicatorList>
                </telerik:RadialScale>
            </telerik:RadialGauge>
        </telerik:RadGauge>
    </Grid>
</UserControl>

using System.Globalization;
using System.Windows;
using System.Windows.Controls;
  
namespace RadControlsSilverlightApp1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
  
            string stringValue = Application.Current.Host.InitParams["needleValue"];
            double value = double.Parse(stringValue, CultureInfo.InvariantCulture);
  
            this.Needle1.Value = value;
        }
    }
}

For more information please take a look to the following articles:
http://msdn.microsoft.com/en-us/library/cc838255(v=vs.95).aspx
http://msdn.microsoft.com/en-us/library/cc645076(v=vs.95).aspx

Best wishes,
Andrey Murzov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Jonathan
Top achievements
Rank 1
answered on 08 Jun 2011, 02:31 AM
How would you set the needle from the .cs file of an aspx page that hosts the silverlight control rather than using an object parameter?
0
Andrey
Telerik team
answered on 09 Jun 2011, 09:46 AM
Hello Jonathan,

I have attached a sample solution that sets the needle value from the .cs file of an aspx page.

I hope it helps.


Kind regards,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonathan
Top achievements
Rank 1
answered on 09 Jun 2011, 02:48 PM
thanks Andrey I'll take a look
0
Jonathan
Top achievements
Rank 1
answered on 17 Jun 2011, 09:01 AM
I took a look at the example project and it works well for setting the intial value.  What I would liek to do is set the valuse every 5 minutes using a timer in the radajax manager.

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="Timer1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadRotator1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="radGridWhosCallingStats" LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="gaugeUserControl1" LoadingPanelID="RadAjaxLoadingPanel1" />                    
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" InitialDelayTime="100" BackgroundPosition="Bottom" Transparency="10" >
            <img src="./images/loading7.gif" alt="Loading..." style="border: 0;"/>
     </telerik:RadAjaxLoadingPanel
    <asp:Panel ID="Panel1" runat="server">
        <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick"/>
    </asp:Panel>


The problem is that it looks like the gauge control value is set with a piece of javascript that is not updated by the timer.  how might I accomplish this?

Thanks,
Jonathan
0
Jonathan
Top achievements
Rank 1
answered on 21 Jun 2011, 06:47 AM

Hello again.

basically the guage user control does a

 

Page.ClientScript.RegisterStartupScript(

 

typeof(Page), "SLPROXY_VALUE" + this.ClientID, string.Format("setGaugeValue('{0}','{1}');", this.GaugeValue, this.ClientID), true);

which inserts the follwoing piece of code into the page on the initial page load

 


//<![CDATA
setGaugeValue('71','ctl00_ContentPlaceHolder1_gaugeUserControl1');


but I'd like to be able to reset the gauge value via the ajax callback from the timer every 5 minutes based on a value returned from a webservice call.  It's a fine piece of work so far could you help me with this last piece.

I'm wondering if using a literal and putting the javascript code in the literal and then having one of the updated controls in the ajax manager be the literal might work.. thoughts?
0
Andrey
Telerik team
answered on 21 Jun 2011, 04:40 PM
Hello Jonathan,

You can take advantage of the RadAjaxManager.ResponseScripts property, as shown in this example.

Best regards,
Ves
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonathan
Top achievements
Rank 1
answered on 21 Jun 2011, 08:05 PM
Thanks, but how would I access the page's radajaxmanager or in the case of your example a radajaxpanel from inside the usercontrol Page_load event as this is where the script is setup?

Cheers
Jonathan
0
Giuseppe
Telerik team
answered on 22 Jun 2011, 02:27 PM
Hello Jonathan,

Check the following help topic here:

If one still needs the manager instance at the code of a WebUserControl for example so that an AJAX request need to be triggered explicitly, she can get the manager by RadAjaxManager.GetCurrent() method call. The method will return null if there is no manager on the page, similar to ASP:ScriptManager implementation.


Regards,
Giuseppe
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonathan
Top achievements
Rank 1
answered on 22 Jun 2011, 04:40 PM
ok this is making my brain hurt.    I can see how having a timer inside the user control and using the ajax proxy and RadAjaxManager.ResponseScripts to repond to the ajaxyified timer click to set the scriptabel value on the silverlight object would probably work,  but the timer is in the main page that holds the usercontrol and that leaves me a bit stumped how to pull al this together... 
0
Giuseppe
Telerik team
answered on 27 Jun 2011, 12:09 PM
Hi Jonathan,

It is possible to get a reference to the Timer from the user control like this:
public partial class WebUserControl : System.Web.UI.UserControl
{
    private Timer Timer
    {
        get
        {
            return this.Page.FindControl("Timer1") as Timer;
        }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.Timer != null)
        {
            this.Timer.Tick += new EventHandler<EventArgs>(timer_Tick);
            this.Unload += new EventHandler(WebUserControl_Unload);
        }
    }
 
    void WebUserControl_Unload(object sender, EventArgs e)
    {
        if (this.Timer != null)
            this.Timer.Tick -= new EventHandler<EventArgs>(timer_Tick);
    }
 
    void timer_Tick(object sender, EventArgs e)
    {
        // ...
    }
}


All the best,
Giuseppe
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Gauge
Asked by
Harry
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Jonathan
Top achievements
Rank 1
Giuseppe
Telerik team
Share this question
or