Declare a Javascript variable globally. Initialise it with the minimum required time and use it in setTimeout function by reinitialising it from the webservice response in the javascript. or also you can call a new setTimeout function which will clear the
Timeout after the required period of time
omerdemir
Member
271 Points
528 Posts
is it possible to call javascript function from webservice?
Apr 01, 2012 03:39 PM|LINK
Hello Guys!
I've a GridView which displaying additional data from database when onmouseover row with javascript tooltip.
When user onmouse javascript function calling webservice which including stringbuilder.
I need that when user onmouse over the tooltip stop the setTimeOut function for prevent dissapear tooltip.
is it possible to clear timeout from webservice?
thanks in advance
--tooltip-- <script type="text/javascript" id="hover.details"> Type.registerNamespace("Demo"); Demo.ToolTip = function (panelid) { this._panelid = panelid; this.x = 0; this.y = 0; } Demo.ToolTip.prototype = { get_PanelID: function () { return this._panelid; }, set_PanelID: function (panelid) { this._panelid = panelid; }, BeginShowToolTip: function (event, diaid) { WebService.GetToolTipText(diaid, this.EndShowToolTip, this.OnError, this.OnTimeOut); this.x = 770; this.y = event.clientY - 200; clearTimeout(hovertimeout); }, EndShowToolTip: function (result) { var pnl = $get(tooltip.get_PanelID()); if (pnl.innerHTML != null) { pnl.innerHTML = result; } else { pnl.HTMLContent = result; } pnl.style.visibility = "visible"; pnl.style.display = "inline"; pnl.style.position = "absolute"; pnl.style.left = tooltip.x + "px"; pnl.style.top = tooltip.y + "px"; }, Hide: function () { hovertimeout = setTimeout(function () { tooltip.HideToolTip() }, 2000); }, HideToolTip: function () { var pnl = $get(this.get_PanelID()) pnl.style.visibility = "hidden"; pnl.style.display = "none"; }, OnError: function (result) { alert(result.get_message()); }, OnTimeOut: function (result) { alert(result); } } Demo.ToolTip.registerClass("Demo.ToolTip"); </script> ----tooltip--- webservice------- public string GetToolTipText(int diaid) { string strConn = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString; SqlConnection cnn = new SqlConnection(strConn); cnn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cnn; cmd.CommandText = "select * from dia1 where diaid=@id"; SqlParameter p = new SqlParameter("@id", diaid); cmd.Parameters.Add(p); SqlDataAdapter ada = new SqlDataAdapter(cmd); DataTable table = new DataTable(); ada.Fill(table); StringBuilder b = new StringBuilder(); b.Append("<table style='background-color:#f3f3f3; border: #336699 3px solid; OnMouseOver=\"clearTimeout(hovertimeout)\" "); b.Append("width:150px; font-size:10pt; font-family:Verdana;' cellspacing='0' cellpadding='3'>"); b.Append("<tr><td colspan='3' style='background-color:#336699; color:white;'>"); b.Append("</td></tr>"); b.Append("</table>"); cnn.Close(); return b.ToString();Ken Tucker
All-Star
16797 Points
2608 Posts
MVP
Re: is it possible to call javascript function from webservice?
Apr 01, 2012 03:58 PM|LINK
no the web service runs on the server and the javascript runs on the client so the webservice could not clear the timeout.
Space Coast .Net User Group
omerdemir
Member
271 Points
528 Posts
Re: is it possible to call javascript function from webservice?
Apr 02, 2012 07:48 AM|LINK
Thanks you for response Ken Tucker!
It wont work even if i ll create external js file?
If yes any other advice?
Regards
ceenu4u
Member
98 Points
29 Posts
Re: is it possible to call javascript function from webservice?
Apr 02, 2012 11:30 AM|LINK
Declare a Javascript variable globally. Initialise it with the minimum required time and use it in setTimeout function by reinitialising it from the webservice response in the javascript. or also you can call a new setTimeout function which will clear the Timeout after the required period of time
omerdemir
Member
271 Points
528 Posts
Re: is it possible to call javascript function from webservice?
Apr 02, 2012 12:29 PM|LINK
Thank you for reply and time ceenu4u.
But i did not understood "webservice response in the javascript"..can you provide rough example?
Regards
Ömer
Allen Li - M...
Star
10411 Points
1196 Posts
Re: is it possible to call javascript function from webservice?
Apr 03, 2012 03:04 AM|LINK
Hi, you can try to stop the setTimeOut function with JavaScript codes directly when mouseover event triggered, for example:
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('#ButtonID').mousemove(function () { clearTimeout(hovertimeout); }); }); </script>If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
omerdemir
Member
271 Points
528 Posts
Re: is it possible to call javascript function from webservice?
Apr 03, 2012 07:06 AM|LINK
Hi Allen Li!
Thank you for your reply!
I added this codes to my page. Bu did not work. are you sure that this codes can pick-up ButtonID which in webservice?
Kindly Regards
Ömer
WEBSERVICE (WebService.cs) using System; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Script.Services; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Text; [WebService(Namespace = "http://microsoft.com/webservices/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] public class WebService : System.Web.Services.WebService { [WebMethod] public string GetToolTipText(int diaid) { string strConn = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString; SqlConnection cnn = new SqlConnection(strConn); cnn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cnn; cmd.CommandText = "select * from dia1 where diaid=@id"; SqlParameter p = new SqlParameter("@id", diaid); cmd.Parameters.Add(p); SqlDataAdapter ada = new SqlDataAdapter(cmd); DataTable table = new DataTable(); ada.Fill(table); StringBuilder b = new StringBuilder(); b.Append("<table style='background-color:#f3f3f3; border: #336699 3px solid;"); b.Append("<tr><td>"); b.Append("<button"); b.Append(" id='Comp'>"); b.Append("</button>"); b.Append("</td></tr>"); b.Append("</td></tr>"); b.Append("</table>"); cnn.Close(); return b.ToString(); } } TOOLTIP (Part Codes of Search.aspx.) <script type="text/javascript" language="javascript" id="Hover.Detail"> Type.registerNamespace("Demo"); Demo.ToolTip = function (panelid) { this._panelid = panelid; this.x = 0; this.y = 0; } Demo.ToolTip.prototype = { get_PanelID: function () { return this._panelid; }, set_PanelID: function (panelid) { this._panelid = panelid; }, BeginShowToolTip: function (event, diaid) { WebService.GetToolTipText(diaid, this.EndShowToolTip, this.OnError, this.OnTimeOut); this.x = 770; this.y = event.clientY - 200; clearTimeout(hovertimeout); }, EndShowToolTip: function (result) { var pnl = $get(tooltip.get_PanelID()); if (pnl.innerHTML != null) { pnl.innerHTML = result; } else { pnl.HTMLContent = result; } pnl.style.visibility = "visible"; pnl.style.display = "inline"; pnl.style.position = "absolute"; pnl.style.left = tooltip.x + "px"; pnl.style.top = tooltip.y + "px"; }, Hide: function () { hovertimeout = setTimeout(function () { tooltip.HideToolTip() }, 5000); }, HideToolTip: function () { var pnl = $get(this.get_PanelID()) pnl.style.visibility = "hidden"; pnl.style.display = "none"; }, OnError: function (result) { alert(result.get_message()); }, OnTimeOut: function (result) { alert(result); } } Demo.ToolTip.registerClass("Demo.ToolTip"); </script>omerdemir
Member
271 Points
528 Posts
Re: is it possible to call javascript function from webservice?
Apr 03, 2012 11:40 AM|LINK
Found Solution.
Yes it is possible.
added functions like this and it is working.
Thank you all!
b.Append("<table onmouseover=' clearTimeout(hovertimeout); ' onmouseout=' tooltip.Hide() ' style='background-color:#f3f3f3; border: #336699 3px solid;");