Professional, Software

Using URL Parameters

URL Parameter is great way to pass the information to html page. Managed OM around HTML DOM makes it really easy for Silverlight application to use those parameters at the start up time.

Page.Xaml

<Canvas
        xmlns="http://schemas.microsoft.com/client/2007" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        x:Name="parentCanvas" 
        Loaded="Page_Loaded" 
        x:Class="UrlParam.Page;assembly=ClientBin/UrlParam.dll"
        Width="640"
        Height="480"
        Background="White"
        >
    <TextBlock x:Name="txtParam" Width="324" Height="27" 
             Canvas.Left="79" Canvas.Top="67" Text="Param:" 
             TextWrapping="Wrap"/>
</Canvas>

Page.xaml.cs

using System;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Collections.Generic;

namespace UrlParam
{
    public partial class Page : Canvas
    {
        public void Page_Loaded(object o, EventArgs e)
        {
            // Required to initialize variables
            InitializeComponent();
            Dictionary<string, string> urlparams = HtmlPage.QueryString as Dictionary<string,string>;
            string s = string.Empty;
            urlparams.TryGetValue("Param1", out s);
            txtParam.Text = "Param1: " + s;
        }
    }
}

Debugging this gets trickier though, I had to launch  browser, then attach debugger to it and then run the browser with URL that has parameters.

Advertisements
Standard

6 thoughts on “Using URL Parameters

  1. Pingback: Recursive Reflection : Using Url Parameters

  2. Pingback: MSDN Blog Postings · Using Url Parameters

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s