Adding mutliple silverlight controls to asp.net ajax site

5 posts, 0 answers
  1. Dave
    Dave avatar
    19 posts
    Member since:
    Nov 2010

    Posted 03 Feb 2011 Link to this post

    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
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 09 Feb 2011 Link to this post

    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>>
  3. Dave
    Dave avatar
    19 posts
    Member since:
    Nov 2010

    Posted 09 Feb 2011 Link to this post

    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
  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 11 Feb 2011 Link to this post

    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>>
  5. Dave
    Dave avatar
    19 posts
    Member since:
    Nov 2010

    Posted 11 Feb 2011 Link to this post

    Works like a 'charm'!  This is much cleaner than having a new project for each silverlight control, thanks...
Back to Top