Desperately Seeking Love of Sophie

Using URL Parameters

with 4 comments

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.

About these ads

Written by Vivek

June 8, 2007 at 7:58 pm

Posted in Professional, Software

Tagged with

4 Responses

Subscribe to comments with RSS.

  1. [...] http://vivekdalvi.wordpress.com/2007/06/08/using-url-parameters/ Posted: Friday, June 08, 2007 9:14 PM by vivekd [...]

  2. very interesting, but I don’t agree with you
    Idetrorce

    Idetrorce

    December 15, 2007 at 2:08 pm

  3. Dictionary urlparams = HtmlPage.Document.QueryString as Dictionary;

    Alexey

    November 21, 2010 at 9:17 pm


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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: