- 넘겨온 쿼리스트링값 받기
    - 순수 HTML에서 JavaScript 사용하지 않고 쿼리스트링 받기 가능





[MainPage.xaml]


<UserControl x:Class="RiaQueryString.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <Button x:Name="btnGet" Content="현재 페이지의 쿼리스트링값 받기" Margin="10" />

    </Grid>

</UserControl>

 

 







[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Browser;

 

namespace RiaQueryString

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            btnGet.Click += new RoutedEventHandler(btnGet_Click);

        }

 

        void btnGet_Click(object sender, RoutedEventArgs e)

        {

            // 현재페이지.htm?Name=Red&Age=21...

            HtmlDocument document = HtmlPage.Document;

            string querystring = "";

            foreach (string key in document.QueryString.Keys)

            {

                querystring += String.Format(" : {0}, : {1}\n", key, document.QueryString[key]);

            }

            MessageBox.Show(querystring);

        }

    }

}

 

 







[실행결과]

--> "RiaQueryStringTestPage.aspx"또는 "RiaQueryStringTestPage.html" 웹 페이지 아무데서나 둘다 쿼리스트링 값(?key=value&key=value...)을 입력해서 실행하면된다.









Posted by holland14
: