Results 1 to 2 of 2

Thread: Adding Javascript Event Issue

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Adding Javascript Event Issue

    I am creating a dropdownList server control in my page load event, using Attributes.Add I assign an onmousedown event.

    This all works perfectly on my local machine. However when deployed to the server the 'event' is always undefined so evt.cancelable throws an error.

    Does anyone know anything that would cause this behaviour difference between environments?


    Code:
     DropDownList ddl = new DropDownList();
          ddl.ID = "ddlChkList";
          ListItem lstItem = new ListItem();
          ddl.Items.Insert(0, lstItem);
          ddl.Width = new Unit(153);
        
          ddl.EnableViewState = true; 
          ddl.Attributes.Add("onmousedown", "showdivonClick(event)");


    Code:
     function showdivonClick(e) {
    
            var objDLL = document.getElementById("maincontent_PrivateEventsSearch_divChkList");
            if (objDLL.style.display == "block")
                objDLL.style.display = "none";
            else
                objDLL.style.display = "block";
    
    
            var evt = e || window.event;
            if (evt.cancelable == 1) {
                alert(String(evt.cancelable));
            }
            else {
                alert(String(evt.cancelable));
            }
    
    
    
    
        }

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Adding Javascript Event Issue

    Hi,

    The code above normally works for declared controls in aspx markup. I haven't tried that when adding controls at runtime.

    Have you checked the values of e and window.event when you deployed it in the server?

    Code:
    alert(e); //check e value
    alert(window.event); //check window.event value
    KGC
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width