referencing a dynamically created HoverMenuExtender

Last post 01-08-2009 10:31 PM by Lehel. 7 replies.

Sort Posts:

  • referencing a dynamically created HoverMenuExtender

    01-03-2009, 6:41 PM
    • Member
      point Member
    • Lehel
    • Member since 07-02-2008, 1:56 AM
    • Posts 10

     I created an ASP.NET server control that creates an UpdatePanel and a HoverMenuExtender.  What I'm trying to do is add a textbox to the UpdatePanel and then have the client-side's onmousever for the textbox load up and show the HoverMenuExtender. 

    I assume that I use the BehaviorID of the HoverMenuExtender inside the client-side javascript onmouseover.  My problem is what to set the BehaviorID to that will be unique among every instance of the Server Control.  If I simply use BehaviorID= this.ID + "HoverMenuExtender",  I don't know how to reference that in the javascript because this.ID is server-side.

  • Re: referencing a dynamically created HoverMenuExtender

    01-04-2009, 12:55 AM
    • Star
      10,827 point Star
    • ps2goat
    • Member since 11-17-2006, 10:43 PM
    • Posts 1,973

    this.ClientID will get you the ID that will be available for the control on the client-side.  so this.ClientID + "HoverMenuExtender" should work.

    ---------------------------------------
    MCP - Web Based Client Development .NET 2.0
  • Re: referencing a dynamically created HoverMenuExtender

    01-04-2009, 3:24 AM
    • Star
      10,558 point Star
    • Danny117
    • Member since 12-16-2008, 2:30 PM
    • Royal Oak Michigan USA
    • Posts 1,837

    Watch the video http://www.asp.net/learn/ajax-videos/video-93.aspx 

    lehel I create ids just like you do.  ASP.NET will get them right on the client if its a user control it will prefix it with something unique its built in.  if you need to code something and bring up the hovermenu with javascript instead of using the build in functionality of hovering over targetcontrolid then make the extender id and the behaviorid different.  think of the behaviorid as shorthand.  it could be as simple as HME001 .

     then on your page your javascript would be

    $find('HME001').onShow();

    ...

    $find('HME001').onHide();

    I looked at the hovermenubehavior.js and I found the onHide and onShow Functions for you

    onHide : function() {
            /// <summary>
            /// Play the OnHide animation
            /// </summary>
            /// <returns />
            if (this._popupBehavior) {
                this._popupBehavior.onHide();
            }
        },

     onShow : function() {
            /// <summary>
            /// Play the OnShow animation
            /// </summary>
            /// <returns />
            if (this._popupBehavior) {
                this._popupBehavior.onShow();
            }
        },

    Good Luck



  • Re: referencing a dynamically created HoverMenuExtender

    01-04-2009, 4:30 PM
    • Member
      point Member
    • Lehel
    • Member since 07-02-2008, 1:56 AM
    • Posts 10

     thanks for the help.  one more question on HoverMenus.  I've only seen examples with GridViews and such. I'm guessing the functionality is used with the "CommandName" property.  I tried to add Click events to the linkbuttons inside the panel but that causes the entire page to refresh when I click on a menu item (not the behavior I wanted).   Is there a way to wire up the LinkButtons so that they are more AJAX style?  i basically want it to have several options but not really sure how to wire that up with CommandName.  any examples or links to do this would be much obliged.

     

    Edit:

     I've been messing around with my custom control and I realize after some reading that the __doPostBack needs to be called with my UpdatePanel.  but for each of my menu items in the HoverMenuExtender,  I notice that its calling __doPostBack with the name of the LinkButton menu item instead--which is doing nothing.

     how do i get the LinkButtons to cause my UpdatePanel to post back?

  • Re: referencing a dynamically created HoverMenuExtender

    01-06-2009, 10:10 PM
    Hi Lehel,

    Please refer to my reply in this thread, any questions, feel free to tell me.
    http://forums.asp.net/p/1366083/2842243.aspx#2842243

    You can also post your related code to help us clear your goal.

    Best regards,

    Zhi-Qiang Ni

    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: referencing a dynamically created HoverMenuExtender

    01-07-2009, 3:09 AM
    • Member
      point Member
    • Lehel
    • Member since 07-02-2008, 1:56 AM
    • Posts 10

    okay so most of this code is still in an experimental stage, thus all the different random lines of code to try and test stuff out.

     

    with that said, this is main class of the ASP.NET server control.  the overall design is an AJAX UpdatePanel containing a textbox and a HoverMenuExtender attached to it.  The functionality i want is to select one of the menu items of the HoverMenu and cause a postback for the UpdatePanel, once i can get that, i can add the code to handle what the UpdatePanel should load next.

     

    My whole reason for using the UpdatePanel and the HoverMenuExtender was within the ASP.NET server control was to avoid doing AJAX/javascript coding myself.

     

    The code below doesn't cause any postback when clicking on the items.  the __doPostBack doesn't reference the UpdatePanel but the menuitems which doesn't have a postback, obviously.

      

    1    [DefaultProperty("Text")]
    2        [ToolboxData("&lt;{0}:MagicText runat=server></{0}:MagicText>")]
    3        public class MagicText : WebControl
    4        {
    5            protected UpdatePanel panel;
    6            protected HoverMenuExtender menu;
    7            private HttpSessionState Session;
    8            protected TextBox textbox;
    9            protected Panel currentMenu;
    10   
    11   
    12           [Bindable(true)]
    13           [Category("Appearance")]
    14           [DefaultValue("")]
    15           [Localizable(true)]
    16           public string Text
    17           {
    18               get
    19               {
    20                   String s = (String)ViewState["Text"];
    21                   return ((s == null) ? "[" + this.ID + "]" : s);
    22               }
    23   
    24               set
    25               {
    26                   ViewState["Text"] = value;
    27               }
    28           }
    29   
    30           protected override void CreateChildControls()
    31           {
    32               panel = new UpdatePanel();
    33               this.Controls.Add(panel);
    34               panel.ID = this.ID + "ajaxPanel";
    35               
    36               panel.UpdateMode = UpdatePanelUpdateMode.Conditional;
    37               panel.ChildrenAsTriggers = true;
    38               panel.Load += new EventHandler(UpdatePanel_OnLoad);
    39               textbox = new TextBox();
    40               textbox.ReadOnly = true;
    41               textbox.ID = this.ID + "textbox";
    42               textbox.Text = Text;
    43               Button b = new Button();
    44               b.CommandName = "hi";
    45               b.Text = "hi";
    46               b.Click += new EventHandler(ButtonClick);
    47               b.ID = "button1";
    48               panel.ContentTemplateContainer.Controls.Add(b);
    49               menu = new HoverMenuExtender();
    50               menu.ID = this.ID + "AjaxHoverMenu";
    51               menu.BehaviorID = this.ID + "AjaxHoverMenuBehavior";
    52               menu.PopupControlID = GetPanelForMenu();
    53               menu.TargetControlID = textbox.ID;
    54               menu.HoverCssClass = "popupHover";
    55               menu.HoverDelay = 25;
    56               menu.PopupPosition = HoverMenuPopupPosition.Right;
    57               panel.ContentTemplateContainer.Controls.Add(textbox);
    58               panel.ContentTemplateContainer.Controls.Add(menu);
    59               panel.ContentTemplateContainer.Controls.Add(currentMenu);
    60   
    61               PostBackTrigger trigger = new PostBackTrigger();
    62               trigger.ControlID = b.ClientID.ToString();
    63               panel.Triggers.Add(trigger);
    64   
    65               base.CreateChildControls();
    66               //panel.Controls.Add(currentMenu);
    67               
    68           }
    69   
    70           void ButtonClick(object sender, EventArgs e)
    71           {
    72           }
    73   
    74           protected string GetPanelForMenu()
    75           {
    76               currentMenu = new Panel();
    77               currentMenu.ID = this.ID + "menuForPopup";
    78               currentMenu.CssClass = "popupMenu";
    79               LinkButton lb;
    80               
    81               lb = new LinkButton();
    82               lb.ID = "magicMenuItem1";
    83               lb.CssClass = "popupItem";
    84               lb.Click += new EventHandler(ModifyText);
    85               lb.Text = "Edit";
    86               currentMenu.Controls.Add(lb);
    87   
    88   
    89               currentMenu.Controls.Add(new LiteralControl("&lt;br/>"));
    90               
    91               lb = new LinkButton();
    92               lb.ID = "magicMenuItem2";
    93               lb.CssClass = "popupItem";
    94               lb.Text = "Add";
    95               //lb.Click += new EventHandler(AddToText);
    96               lb.CommandName = "Add";
    97               currentMenu.Controls.Add(lb);
    98   
    99               currentMenu.Controls.Add(new LiteralControl("&lt;br/>"));
    100  
    101              lb = new LinkButton();
    102              lb.ID = "magicMenuItem3";
    103              lb.CssClass = "popupItem";
    104              lb.Click += new EventHandler(TranslateText);
    105              lb.Text = "Translate";
    106              currentMenu.Controls.Add(lb);
    107  
    108              currentMenu.Controls.Add(new LiteralControl("&lt;br/>"));
    109  
    110              lb = new LinkButton();
    111              lb.ID = "magicMenuItem4";
    112              lb.CssClass = "popupItem";
    113              lb.Click += new EventHandler(CommentText);
    114              lb.Text = "Comment";
    115              currentMenu.Controls.Add(lb);
    116  
    117              currentMenu.Controls.Add(new LiteralControl("&lt;br/>"));
    118  
    119              lb = new LinkButton();
    120              lb.ID = "magicMenuItem5";
    121              lb.CssClass = "popupItem";
    122              lb.Click += new EventHandler(FlagText);
    123              lb.Text = "Flag";
    124              currentMenu.Controls.Add(lb);
    125  
    126              currentMenu.Controls.Add(new LiteralControl("&lt;br/>"));
    127  
    128              lb = new LinkButton();
    129              lb.ID = "magicMenuItem6";
    130              lb.CssClass = "popupItem";
    131              lb.Click += new EventHandler(ViewRevisionHistory);
    132              lb.Text = "View Revisions";
    133              currentMenu.Controls.Add(lb);
    134  
    135              currentMenu.Controls.Add(new LiteralControl("&lt;br/>"));
    136  
    137              return currentMenu.ID;
    138          }
    139  
    140          void UpdatePanel_OnLoad(object sender, EventArgs e)
    141          {
    142              int x = 0;
    143              x = x;
    144          }
    145  
    146          void ModifyText(object sender, EventArgs e)
    147          {
    148              textbox.ReadOnly = false;
    149              textbox.BackColor = Color.Pink;
    150          }
    151  
    152          void AddToText(object sender, EventArgs e)
    153          {
    154              throw new NotImplementedException();
    155          }
    156  
    157          void TranslateText(object sender, EventArgs e)
    158          {
    159              throw new NotImplementedException();
    160          }
    161  
    162          void CommentText(object sender, EventArgs e)
    163          {
    164              throw new NotImplementedException();
    165          }
    166  
    167          void FlagText(object sender, EventArgs e)
    168          {
    169              throw new NotImplementedException();
    170          }
    171  
    172          void ViewRevisionHistory(object sender, EventArgs e)
    173          {
    174              throw new NotImplementedException();
    175          }
    176  
    177  
    178          protected override void RenderContents(HtmlTextWriter output)
    179          {
    180              panel.RenderControl(output);
    181              currentMenu.RenderControl(output);
    182          }
    183  
    184          void RenderMenu(HtmlTextWriter writer)
    185          {
    186              base.Render(writer);
    187          }
    188      }
    
     
  • Re: referencing a dynamically created HoverMenuExtender

    01-08-2009, 3:20 AM
    Answer
    Hi Lehel,

    I have tested your code locally and found the cause is the CustomControl has not implemented the INamingContainer interface. Custom control MUST implement this Marker interface if it needs to handle any of its child control's events. There is nothing to do with the AjaxControlToolkit and the UpdatePanel.

    Here is some useful links:

    http://www.dotnetjunkies.com/WebLog/srivallichavalidotnet/archive/2005/11/14/133759.aspx
    http://msdn.microsoft.com/en-us/library/system.web.ui.inamingcontainer.aspx

    Best regards,

    Zhi-Qiang Ni

    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: referencing a dynamically created HoverMenuExtender

    01-08-2009, 10:31 PM
    • Member
      point Member
    • Lehel
    • Member since 07-02-2008, 1:56 AM
    • Posts 10

     Thank you.  That worked.  I guess I will read up on all those inheritable interfaces since that was a pretty esoteric fix for me.

Page 1 of 1 (8 items)