Using Javascript to fire an event in another class....?
-
Hi, I'm currently working on a website that has a treeview that represents folders in a virtual directory and also a datalist that allows users view files in a given folder, or text search, etc. I am using ASP.NET and C# and hope to implement a function where if the mouse is hovering over an imagebutton in the datalist - the folder for that given file will be highlighted in the TreeView. The TreeView and DataList are kept in diffent controls (ascx files) so I have been using EventHandlers in trying to solve my problem. Also, as far as I can tell - ASP.NET does not contain an 'onmouseover' attribute for ImageButtons so I have been using JavaScript to detect and fire the event. The DataList is kept in its own control, which is then placed into its parent control that also holds the TreeView. There is a lot of code so I will try and submit the code that I think is relevant: DataList Control.aspx: (javascript) function highlightNode(event) { javascript:setTimeout('__doPostBack(\'<% =btnCheat.ClientID %>\',\'\')',0) // alert(event); } function mouseOut(event) { javascript:setTimeout('__doPostBack(\'<% =btnMouseOutCheat.ClientID %>\',\'\')',0) //alert("mouseOut") } This is where I believe I may be going wrong - the setTimeout means that the highlightNode function is repeatedly called with onmouseover, could someone advise on how to rewrite this diffently so that it does not repeatedly call a method? The post backs called on each of these functions simulate the clicking of asp:buttons that will enable me to access the code-behind from the onmouseover event, here is the code-behind for the DataList control. DataList.ascx.cs: imgBtnFileType.Attributes["onmouseover"] = "highlightNode('" + HoverID + "')"; imgBtnFileType.Attributes["onmouseout"] = "mouseOut(event)"; These attributes are added in the ItemDataBound method for the DataList, where I add onmouseover and onmouseout to my image button. HoverID is the value I am passing to the event and is a ViewState variable that will be used to identify the Folder that I wish to highlight. protected void btnCheat_Click(object sender, EventArgs e) { RaiseMouseOverEvent(); } protected void btnMouseOutCheat_Click(object sender, EventArgs e) { HoverID = 0; RaiseMouseOutEvent(); } Above are the events called when I simulate a button click with my javascript. public EventHandler evtMouseOver; public EventHandler evtMouseOut; Again, I am using Even
-
Hi, I'm currently working on a website that has a treeview that represents folders in a virtual directory and also a datalist that allows users view files in a given folder, or text search, etc. I am using ASP.NET and C# and hope to implement a function where if the mouse is hovering over an imagebutton in the datalist - the folder for that given file will be highlighted in the TreeView. The TreeView and DataList are kept in diffent controls (ascx files) so I have been using EventHandlers in trying to solve my problem. Also, as far as I can tell - ASP.NET does not contain an 'onmouseover' attribute for ImageButtons so I have been using JavaScript to detect and fire the event. The DataList is kept in its own control, which is then placed into its parent control that also holds the TreeView. There is a lot of code so I will try and submit the code that I think is relevant: DataList Control.aspx: (javascript) function highlightNode(event) { javascript:setTimeout('__doPostBack(\'<% =btnCheat.ClientID %>\',\'\')',0) // alert(event); } function mouseOut(event) { javascript:setTimeout('__doPostBack(\'<% =btnMouseOutCheat.ClientID %>\',\'\')',0) //alert("mouseOut") } This is where I believe I may be going wrong - the setTimeout means that the highlightNode function is repeatedly called with onmouseover, could someone advise on how to rewrite this diffently so that it does not repeatedly call a method? The post backs called on each of these functions simulate the clicking of asp:buttons that will enable me to access the code-behind from the onmouseover event, here is the code-behind for the DataList control. DataList.ascx.cs: imgBtnFileType.Attributes["onmouseover"] = "highlightNode('" + HoverID + "')"; imgBtnFileType.Attributes["onmouseout"] = "mouseOut(event)"; These attributes are added in the ItemDataBound method for the DataList, where I add onmouseover and onmouseout to my image button. HoverID is the value I am passing to the event and is a ViewState variable that will be used to identify the Folder that I wish to highlight. protected void btnCheat_Click(object sender, EventArgs e) { RaiseMouseOverEvent(); } protected void btnMouseOutCheat_Click(object sender, EventArgs e) { HoverID = 0; RaiseMouseOutEvent(); } Above are the events called when I simulate a button click with my javascript. public EventHandler evtMouseOver; public EventHandler evtMouseOut; Again, I am using Even
b>You can raise server side event when the mouse over the imagebutton. function Show() { document.getElementById('<%=ImageButton1.ClientID%>').click(); } ServerSide code protected void Page_Load(object sender, EventArgs e) { ImageButton1.Attributes.Add("onmouseover", "Show();"); } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { // Write your event handler... }
Shanmugam R
-
b>You can raise server side event when the mouse over the imagebutton. function Show() { document.getElementById('<%=ImageButton1.ClientID%>').click(); } ServerSide code protected void Page_Load(object sender, EventArgs e) { ImageButton1.Attributes.Add("onmouseover", "Show();"); } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { // Write your event handler... }
Shanmugam R
I want to be able to raise an event without actually clicking on the image buttons - which is why I am including buttons that do nothing but raise the event when the image button is hovered over. -- I've now managed to highlight the node by hovering over the image button using the line of code from the previous post (below). document.getElementById('<%=btnMouseOutCheat.ClientID %>').click(); Only as before, the mouseover event is continually raised when this happens - when I only really want to fire the event once on mouseover and again with mouseout. Any ideas anyone? -- modified at 9:16 Friday 26th October, 2007
-
I want to be able to raise an event without actually clicking on the image buttons - which is why I am including buttons that do nothing but raise the event when the image button is hovered over. -- I've now managed to highlight the node by hovering over the image button using the line of code from the previous post (below). document.getElementById('<%=btnMouseOutCheat.ClientID %>').click(); Only as before, the mouseover event is continually raised when this happens - when I only really want to fire the event once on mouseover and again with mouseout. Any ideas anyone? -- modified at 9:16 Friday 26th October, 2007
-
The whole DataList control (ascx file) is enclosed in an UpdatePanel in the parent control - and I am having the problem that I already mentioned. Do you mean that I need to use an ashx handler? If so, any ideas how I might go about writing that? thanks, Dave