Passing values to and from aspx pages

There maybe a few cases where you may want to pass values between the silverlight control and the containing aspx page. For example clicking on a button on the aspx page to zoom the map to a specific feature, or clicking along a feature on the map and bring related data back to the aspx page.

Sending a request to the Silverlight MapControl

To send a request to the MapControl follow these steps:
  • Make sure you set the value of the RequestControlID XAML parameter (see XAML control parameters) to a valid textbox in your aspx page. Lets say its called txtSLRequests.
  • Ensure you have the mapControl inside an update panel. In this example called upnlSL
  • You can then set the OnClick event on the button to run something similar to:

 protected void ZoomToStreet(string street_name)
 {
     txtSLRequests.Text = "action=\"AttributeQuery\" layer=\"STREETS\" where=\"SEG_NAME = '" + street_name + "'\"";
     upnlSL.Update();
 }

If you downloaded the source code or compiled application you should be able to test this by entering in the second text box -below the map- the following string:
action="AttributeQuery" layer="kalamaria_blocks" where="ID=8381"
and then press [Enter]. The map should zoom and highlight one of the building blocks in the map.

Receiving a request from the MapControl

To receive information form the MapControl follow these steps:
  • Make sure you set the value of the TargetControlID XAML parameter (see XAML control parameters) to a valid textbox in your aspx page.
  • In your mapfile set XLINKFIELD value to a valid field for the layer(s) you want to sent values to the containter page. (See also the Mapfile-specific functionality topic).
  • If you now make the layer active from the legend (by pressing on each name) and then you click on the identify button, the identify dialog will display an additional "Show Details" button show_details.png. When you press this button, the external textbox defined (TargetControlID) will be populated with the value of this field. From then you can use javascript events like onfocus() or onblur() (usually the second works better) to cause a postback and say display a ASP.NET data grid control with the attribute details of the clicked feature.

You should be able to test this in the sample application by making the Signs layer active, use the identify tool to click on a sign, select it from the identify grid and then click the show_details.png button. The first text box below the map should display a number which is the value of the XLINKFIELD field defined.

Last edited Nov 17, 2009 at 12:36 PM by gaiocorp, version 10

Comments

No comments yet.