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

Adding mutliple silverlight controls to asp.net ajax site

4 Answers 44 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 03 Feb 2011, 06:14 PM
I have found examples of adding a silverlight RadGauge to an Asp.net Ajax web site and have implemented it and all is working fine.  Now I want to add another silverlight control to the same web site but can't seem to find out how that is done.  I have a silverlight project in my solution and it creates the .xap file that I include in my .aspx page to get the Gauge to show as follows:

<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilvrLghtInASP.NET.xap"
       MinimumVersion="2.0.30728.0" Width="90%" Height="90%" OnPluginLoaded="pluginLoaded" />

That .xap file contained a RadGauge and that is showing on the page fine.  Now I want to add a RadChart else where on the site, do I need to create a whole new silverlight project with the just the chart in it.  Since the line above doesn't refer to any particular control in the xap project, I'm thinking I need a new project (and therefore a new .xap file) for each seperate control I want to add, is this correct?  Is there a way of adding controls to a single silverlight project and only showing the one I want to see in the different pages of my asp.net site?  I cannot find any examples of this...
Thanks in advance

4 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 09 Feb 2011, 09:49 AM
Hello Dave,

That would be the easier approach.
As you know, the .xap file contains the assembly of your Silverlight project. That assembly has an Application class (usually class App) which sets its RootVisual element to the one of the user controls in the project:

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new MainPage();
}
the MainPage is the control that hosts your RadGauge for example.
So, as you suggested, you need to create another SL project and use the other controls in it. Then copy the generated xap to a folder that will be used by the other asp.net page.

Hope this helps.

All the best,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Dave
Top achievements
Rank 1
answered on 09 Feb 2011, 03:42 PM
Hi,

Thanks for the reply...  One thing, and I suppose this may be more of a Silverlight question than a Telerik one but;
could I somehow have a condition in the App startup function that might help to do what I want, ie.

private void Application_Startup(object sender, StartupEventArgs e)
{
    if(some check)
        this.RootVisual = new GaugePage();
    else
        this.RootVisual = new GraphPage();
}

perhaps the sender or the args has something I could check?  I guess part of the question would be when is this event called and would it only be called once or once per control or once per page or ...  ?

Thanks again,
Dave
0
Veselin Vasilev
Telerik team
answered on 11 Feb 2011, 03:25 PM
Hello Dave,

Yes, that would be possible. Please check this tutorial on the matter.

All the best,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Dave
Top achievements
Rank 1
answered on 11 Feb 2011, 05:05 PM
Works like a 'charm'!  This is much cleaner than having a new project for each silverlight control, thanks...
Tags
General Discussions
Asked by
Dave
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Dave
Top achievements
Rank 1
Share this question
or