Ce sujet n'a pas encore été évalué - Évaluez ce sujet

ImageMapEventArgs, classe

Fournit des données pour l'événement Click d'un contrôle ImageMap.

Espace de noms: System.Web.UI.WebControls
Assembly : System.Web (dans system.web.dll)

public class ImageMapEventArgs : EventArgs
public class ImageMapEventArgs extends EventArgs
public class ImageMapEventArgs extends EventArgs
Non applicable.

L'événement Click est déclenché suite à un clic sur un objet HotSpot d'un contrôle ImageMap. Pour permettre à un objet HotSpot de déclencher l'événement Click, vous devez d'abord affecter HotSpotMode.PostBack à la propriété ImageMap.HotSpotMode ou la propriété HotSpot.HotSpotMode. Pour contrôler par programme les actions effectuées lorsqu'un clic est effectué sur un HotSpot de publication, fournissez un gestionnaire d'événements pour l'événement Click.

Une propriété PostBackValue stocke une chaîne associée au comportement de l'objet HotSpot lorsqu'un clic est effectué dessus. Cette chaîne est passée dans les données d'événement ImageMapEventArgs en cas de clic sur HotSpot.

L'exemple de code suivant montre comment créer un gestionnaire d'événements pour l'événement Click. Le contrôle ImageMap contient deux objets RectangleHotSpot. La propriété ImageMap.HotSpotMode a la valeur HotSpotMode.PostBack, ce qui a pour effet de publier la page sur le serveur chaque fois qu'un utilisateur clique sur l'un des objets RectangleHotSpot. L'événement Click est géré par le gestionnaire d'événements VoteMap_Clicked. VoteMap_Clicked examine la propriété PostBackValue envoyée dans les données ImageMapEventArgs pour déterminer l'objet RectangleHotSpot associé à l'événement. Pour que cet exemple fonctionne correctement, vous devez fournir votre propre image pour la propriété ImageUrl et mettre à jour le chemin d'accès de l'image de façon à ce que l'application puisse la localiser.

<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  
  void VoteMap_Clicked (Object sender, ImageMapEventArgs e)
  {
    string coordinates;
    string hotSpotType;
    int yescount = ((ViewState["yescount"] != null)? (int)ViewState["yescount"] : 0);
    int nocount = ((ViewState["nocount"] != null)? (int)ViewState["nocount"] : 0);

    // When a user clicks the "Yes" hot spot,
    // display the hot spot's name and coordinates.
    if (e.PostBackValue.Contains("Yes"))
    {
      yescount += 1;
      coordinates = Vote.HotSpots[0].GetCoordinates();
      hotSpotType = Vote.HotSpots[0].ToString ();
      Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
                      "The coordinates are " + coordinates + ".<br />" +
                      "The current vote count is " + yescount.ToString() + 
            " yes votes and " + nocount.ToString() + " no votes.";
    }
      
    // When a user clicks the "No" hot spot,
    // display the hot spot's name and coordinates.
    else if (e.PostBackValue.Contains("No"))
    {
      nocount += 1;
      coordinates = Vote.HotSpots[1].GetCoordinates();
      hotSpotType = Vote.HotSpots[1].ToString ();
      Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
                      "The coordinates are " + coordinates + ".<br />" +
            "The current vote count is " + yescount.ToString() +
            " yes votes and " + nocount.ToString() + " no votes.";
    }
    
    else
    {
      Message1.Text = "You did not click a valid hot spot region.";
    }

    ViewState["yescount"] = yescount;
    ViewState["nocount"] = nocount;
  }           
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>ImageMap Class Post Back Example</title>
</head>
  <body>
    <form id="form1" runat="server">
    
      <h3>ImageMap Class Post Back Example</h3>
      
      <asp:imagemap id="Vote"           
        imageurl="Images/VoteImage.jpg"
        width="400" 
        height="200" 
        alternatetext="Vote Yes or No"
        hotspotmode="PostBack"
        onclick="VoteMap_Clicked"
        runat="Server">            
          
        <asp:RectangleHotSpot          
          top="0"
          left="0"
          bottom="200"
          right="200"
          postbackvalue="Yes"
          alternatetext="Vote yes">
        </asp:RectangleHotSpot>
          
        <asp:RectangleHotSpot 
          top="0"
          left="201"
          bottom="200"
          right="400"
          postbackvalue="No"
          alternatetext="Vote no">
        </asp:RectangleHotSpot>
      
      </asp:imagemap>
            
      <br /><br />
          
      <asp:label id="Message1"
        runat="Server">
      </asp:label>                 
                 
    </form>      
  </body>
</html>

  • AspNetHostingPermission  pour fonctionner dans un environnement hébergé. Valeur de demande : LinkDemand ; valeur d'autorisation : Minimal.
  • AspNetHostingPermission  pour fonctionner dans un environnement hébergé. Valeur de demande : InheritanceDemand ; valeur d'autorisation : Minimal.
System.Object
   System.EventArgs
    System.Web.UI.WebControls.ImageMapEventArgs
Les membres statiques publics (Shared en Visual Basic) de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Microsoft .NET Framework 3.0 est pris en charge sur Windows Vista, Microsoft Windows XP SP2 et Windows Server 2003 SP1.

.NET Framework

Prise en charge dans : 3.0, 2.0
Cela vous a-t-il été utile ?
(1500 caractères restants)

Ajouts de la communauté

AJOUTER
© 2013 Microsoft. Tous droits réservés.