ASP.NET TreeView code that works in all browsers except Firefox

The following .NET 4.0 code functions perfectly in IE9, Chrome 20 and Opera 12 but fails miserably in Firefox 13. All the browsers are default installs without plugins.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <asp:TreeView ID="Treeview1" Runat="server" 
            onclick="javascript:postBackByObject()"
            ontreenodecheckchanged="Treeview1_TreeNodeCheckChanged" 
            ShowCheckBoxes="All" >
            <Nodes>
              <asp:TreeNode Value="Child1" Expanded="True" Text="1">
                <asp:TreeNode Value="Grandchild1" Text="A" />
                <asp:TreeNode Value="Grandchild2" Text="B" />
             </asp:TreeNode>
               <asp:TreeNode Value="Child2" Text="2" />
               <asp:TreeNode Value="Child3" Expanded="True" Text="3">
               <asp:TreeNode Value="Grandchild1" Text="A" />
             </asp:TreeNode>
            </Nodes>
       </asp:TreeView>
       <asp:TextBox ID="TextBox1" runat="server" Height="156px" TextMode="MultiLine" 
            Width="295px"></asp:TextBox>
    </div>
    </form>
 </body>
  <script language="javascript" type="text/javascript">
      function postBackByObject() {
         var o = window.event.srcElement;
         if (o.tagName == "INPUT" && o.type == "checkbox") {
             __doPostBack("", "");
         }
     }
 </script>
 </html>

I am trying to catch the TreeNode checkbox events with the following code behind:

  protected void Treeview1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
  {
     TextBox1.Text += e.Node.Text;
  }

This is quite annoying - any solution is welcome!

Answers


try handling the event more generically, so it works in both FF and other browsers.

e.g.

onclick="javascript:postBackByObject(event)"

function postBackByObject(e) {
    var evt = e || window.event;
    var o = evt.target || evt.srcElement; 
    if (o.tagName == "INPUT" && o.type == "checkbox") {
        __doPostBack("", "");
    }
}

edit i forgot to add a line for target / srcElement


Need Your Help

Django 1.9 cannot connect to the MySQL server (blank screen)

python mysql django

I recently upgraded the MySQL version to 5.7.11 and Django to 1.9.2.

Python 3.4: contour plot display on dynamic map using unstack and mplleaflet

python matplotlib contour geopandas

I am having a problem getting a contour plot to display on top of an mplleaflet map. I am fairly certain this is because I'm not sure how to tell mplleaflet where to orient my contour plot on the m...