Beispiel #1
0
        /// <summary>
        /// This is used to add a dynamic image area on the initial page load
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lblEnabledMsg.Text = "Image map enabled";

                // Add a dynamic image area.  This is only created once when the page is first loaded.  On post
                // backs, the area is recreated from view state.
                ImageAreaRectangle r = new ImageAreaRectangle(new Rectangle(40, 57, 20, 20));

                r.Action    = AreaClickAction.PostBack;
                r.ToolTip   = "Area 5 (Dynamically added)";
                r.AccessKey = "5";
                r.Attributes.Add("onmouseover", "javascript: IM_Highlight(5);");
                r.Attributes.Add("onmouseout", "javascript: IM_Highlight(0);");

                // Tell the item to mark all properties as dirty so that it is restored entirely from view state
                // on post backs.  If not done, you must recreate the area on post backs.
                r.MarkAsDirty();

                imClickMap.Areas.Add(r);
            }

            // The Visual Studio designer loses the custom attributes on the image area controls in the HTML when
            // the collection editor is used.  This happens to ListItem objects in controls such as the ListBox
            // and DropDown controls too.  The only workaround is to set such attributes in code as shown below
            // when the page loads.
            ((ImageAreaBase)imClickMap.Areas[0]).Attributes.Add("onmouseover", "javascript: IM_Highlight(1);");
            ((ImageAreaBase)imClickMap.Areas[0]).Attributes.Add("onmouseout", "javascript: IM_Highlight(0);");
            ((ImageAreaBase)imClickMap.Areas[1]).Attributes.Add("onmouseover", "javascript: IM_Highlight(2);");
            ((ImageAreaBase)imClickMap.Areas[1]).Attributes.Add("onmouseout", "javascript: IM_Highlight(0);");
            ((ImageAreaBase)imClickMap.Areas[2]).Attributes.Add("onmouseover", "javascript: IM_Highlight(3);");
            ((ImageAreaBase)imClickMap.Areas[2]).Attributes.Add("onmouseout", "javascript: IM_Highlight(0);");
            ((ImageAreaBase)imClickMap.Areas[3]).Attributes.Add("onmouseover", "javascript: IM_Highlight(4);");
            ((ImageAreaBase)imClickMap.Areas[3]).Attributes.Add("onmouseout", "javascript: IM_Highlight(0);");
        }