how can i use an image mouseover to change a multiview.activeviewindex ?

Last post 03-05-2008 2:19 AM by Vince Xu - MSFT. 1 replies.

Sort Posts:

  • how can i use an image mouseover to change a multiview.activeviewindex ?

    03-03-2008, 8:25 AM
    • Loading...
    • orion846
    • Joined on 12-28-2006, 2:39 PM
    • Posts 126

    ImageButton1.Attributes.Add("onmouseover", "this.src='images/layout3a_19.gif'");
    ImageButton1.Attributes.Add("onmouseout", "this.src='images/layout3_19.gif'");

    the above if how i use image mouseover effects for my images, however now i'd like to run code-behind on a mouseover, specifically, i want to have 4 images, 4 views in a multiview. on mouseover of imagebutton1, multiview1.activeviewindex = 0, etc etc.

    anyone know how i can go about this? i'm using AJAX so i realize i'd need to put the MV in an updatepanel.

    thanks in advance for any help 

  • Re: how can i use an image mouseover to change a multiview.activeviewindex ?

    03-05-2008, 2:19 AM
    Answer

     Hi,

    You can use doPostBack in JavaScript to trigger a function in CodeBehind.

    ImageButton1.Attributes.Add("onmouseover", "javascript:__doPostBack('ImageButton1','onmouseover')");

     Code Behind:

    In Page_Load, it needs to retrieve the doPostBack.

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["__EVENTTARGET"] != null)
            {
                string target = Request.Params["__EVENTTARGET"].ToString();

                string passedArgument = Request.Params["__EVENTARGUMENT"].ToString();
                if (target == "ImageButton1" && passedArgument == "onmouseover")
                {
                      multiview1.activeviewindex = 0;
                }
            }
        }

    And then you should define __doPostback JavaScript function.

    If you page contains a Linkbutton control, it will be generated by ASP.NET. If not, you should create it manually. Define two hidden controls is necessary.

    <script language="javascript">
    function __doPostBack(eventTarget, eventArgument)
    {
             var theform;
             if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
                  theform = document.forms["form1"];
             }
             else {
                  theform = document.form1;
             }
             theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
             theform.__EVENTARGUMENT.value = eventArgument;
             theform.submit();
         }
    </script>

    <body>

        <form id="form1" runat="server">

    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

    <asp:ImageButton ID="ImageButton1"  runat="server" ImageUrl="" />

    Hope it helps.

     

    Sincerely,
    Vince Xu
    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.
Page 1 of 1 (2 items)