开发者

javascript onmouseover inside masterpage problem

开发者 https://www.devze.com 2023-03-12 20:37 出处:网络
Hi I\'m currently working on a asp.net project and I need to make a button which when the user moves the cursor from left to right or right to left a hidden text field is filled and then a dopostback

Hi I'm currently working on a asp.net project and I need to make a button which when the user moves the cursor from left to right or right to left a hidden text field is filled and then a dopostback is called for the serverside to read the value of that hidden field.

My problem is that when I create the event listener it doesn't call, thus the pageX does not work. I'm currently testing on Google chrome browser, I've tested the clientX part in the IE and works well.

This is the .aspx side of the cording

<asp:Button ID="Button2" runat="server" Text="<<<------          ------>>>" 
  Width="50%" Height="60px" onclick="Button2_Click" 
  onmouseover="getMouseXY()" onmouseout="getMouseOut()"/>   


  <script type="text/javascript">
        var IE = document.all?true:false;
        var dayD = 0;
        var inCordX = 0;
        var outCordX = 0;                

        if (!IE) 
        document.captureEvents(Event.MOUSEMOVE)                 

        function getMouseOut(e){    
            if (IE) {outCordX = event.clientX + document.body.scrollLeft;}
            else {outCordX = e.pageX;}                                                   
            if(inCordX>outCordX){dayD=1;}else{dayD=-1;}           
            document.getElementById("outputResult").value = dayD;                        
            __doPostBack("","");
        }       

        function getMouseXY(e) {        
          开发者_运维问答  if (IE) {inCordX = event.clientX + document.body.scrollLeft;}
            else {inCordX = e.pageX;}              
            alert(inCordX);
            return true;
        }
    </script>

This is the coding aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {            
        if ((Request.Form["outputResult"] == "-1")
           ||(Request.Form["outputResult"] == "-1"))
        {
            Button2_Click(this, new EventArgs());
        }

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Button2.Text = Request.Form["outputResult"] + "";
    }


Not so sure, but try

  onmouseover="getMouseXY" onmouseout="getMouseOut"/> 

instead of

  onmouseover="getMouseXY()" onmouseout="getMouseOut()"/> 
0

精彩评论

暂无评论...
验证码 换一张
取 消