Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Passing Querystring Parameters to a Silverlight Control

Two good screencasts on passing parameters to a Silverlight 2.0 Control are available on Silverlight.Net. The first from Mike Taulty demonstrates InitParameters as a property in the ASPX Silverlight control.  The second from Tim Heuer demonstrates using InitParameters as well as how to pass in Querystring parameters. Both are worth a look.

The approach to passing Querystring parameters to a Silverlight 2.0 Control that works for me is pretty simple.  We check for the presence of Querystrings in the app.xaml Application_Startup using the Silverlight HTML Bridge and pass those values to the page's constructor.


APP.XAML --------------------------------

private void Application_Startup(object sender, StartupEventArgs e)
{
    int fid = HtmlPage.Document.QueryString["fid"] != null ?
        int.Parse(HtmlPage.Document.QueryString["fid"].ToString()) : -1;
    int pid = HtmlPage.Document.QueryString["pid"] != null ?
        int.Parse(HtmlPage.Document.QueryString["pid"].ToString()) : -1;

    this.RootVisual = new InField.Grid(fid, pid);

}


GRID.XAML STARTUP PAGE -----------------------

private int employeeID = 1;
private int postID = 1;

public Grid(int _employeeID, int _postID)
{

    employeeID = _employeeID;
    postID = _postID;

    InitializeComponent();
    PopulateGrid();
    editing = false;
}


That's the rough cut.  The videos cover additional concepts.  Tim Heuer's video includes downloadable sample code in both VB and C#.  Lots of useful information also in MSDN Library "Intergrating Silverlight with a Web Page."

Comments (3) | Post RSS RSS comment feed

Posted on 10/28/2008 7:28:21 PM by Dave Burke
Categories: .NET | Silverlight
Tags: No tags for this post

Related posts

Comments

10/29/2008 2:25:30 AM Permalink

Pingback from mgalinks.wordpress.com

2008 October 29 - Links for today « My (almost) Daily Links

mgalinks.wordpress.com |

10/29/2008 10:42:15 PM Permalink

Trackback from Community Blogs

Silverlight Cream for October 29, 2008 - 3 -- #413

Community Blogs |

5/20/2010 11:37:38 AM Permalink

Pingback from 461.defutbolazo.com

B1500 Floor Safe Installation Solid Steel, Taillight Toyota Pickup Dodge B150

461.defutbolazo.com |

Comments are closed

This site was built with the Sueetie .NET Online Community Framework. Learn more about Sueetie at Sueetie.com.