ToolTip for dropdownlist (c#)
-
Hi, Can anyone give me the code snippet to provide tooltip for dropdownlist (in c#). Though the dropdownlist does not have a tool tip property I have seen some samples on the net on how to set tooltip for dropdownlist (using javascript) but when i try them i am unable to get the tooltip. Thanks in advance, Sarah
-
Hi, Can anyone give me the code snippet to provide tooltip for dropdownlist (in c#). Though the dropdownlist does not have a tool tip property I have seen some samples on the net on how to set tooltip for dropdownlist (using javascript) but when i try them i am unable to get the tooltip. Thanks in advance, Sarah
-
it has a tooltip property Like I said a long time agao extend the drop down list and override the OnSelectedIndexChanged event 1 line of code equals many bugs. So don't write any!! -- modified at 13:59 Tuesday 7th February, 2006
Hi, Thanks a lot for ur reply.I am a .net newbie so i did'nt quite get what u said so can u be more elaborate or give a sample? Thanks, Sarah -- modified at 5:00 Friday 10th February, 2006
-
Hi, Thanks a lot for ur reply.I am a .net newbie so i did'nt quite get what u said so can u be more elaborate or give a sample? Thanks, Sarah -- modified at 5:00 Friday 10th February, 2006
ok so public class MyDropDownList : DropDownList { public override void OnSelectedIndexChanged( EventArgs e ) { ...something like... this.ToolTip = this.SelectedIndex.ToString(); base.OnSelectedIndexChanged( e ); } } So sarah what this does is: We override the method to add some code to it. So, first set set the tooltip to be the same value at the index. And then call the base so the control operates as normal. You can change the tooltip to anything you want. this was just the easiet to type 1 line of code equals many bugs. So don't write any!!
-
ok so public class MyDropDownList : DropDownList { public override void OnSelectedIndexChanged( EventArgs e ) { ...something like... this.ToolTip = this.SelectedIndex.ToString(); base.OnSelectedIndexChanged( e ); } } So sarah what this does is: We override the method to add some code to it. So, first set set the tooltip to be the same value at the index. And then call the base so the control operates as normal. You can change the tooltip to anything you want. this was just the easiet to type 1 line of code equals many bugs. So don't write any!!
Hi, I have added the following code.Id of DropDownList is DropDownList1 and i have set the autopostback property to true. public class DropDownList1 : DropDownList { protected override void OnSelectedIndexChanged( EventArgs e ) { this.ToolTip = this.SelectedIndex.ToString(); base.OnSelectedIndexChanged( e ); } } When i bring the mouse pointer over the dropdownlist the tool tip does not appear.Am I missing something? Please help. Thanks in advance, Sarah
-
Hi, I have added the following code.Id of DropDownList is DropDownList1 and i have set the autopostback property to true. public class DropDownList1 : DropDownList { protected override void OnSelectedIndexChanged( EventArgs e ) { this.ToolTip = this.SelectedIndex.ToString(); base.OnSelectedIndexChanged( e ); } } When i bring the mouse pointer over the dropdownlist the tool tip does not appear.Am I missing something? Please help. Thanks in advance, Sarah
Ok well your right. Oddly enough the list control doesn't register the attributes. So basically what you should do is to create a DIV object with absolute positioning. The using the Addributes.Add and delete you can set it on the "onMouseOver" event. To sum it up 1) create a DIV, name it something like myToolTip and inside create a SPAN element 2) create the javascript function document.getElementByID('myToolTip').getElelmentByTagName('mySpan').innerText = myToolText; 3) then just add an attribute to the control to display Attribute.Add("onMouseOver", "javascript: callMyJavascriptFunction('myToolText'); I add the code inside the protected Render method of the control and out put all the data needed. You can just as easliy put it inside the Page_Load event of the form here's a link that does the same thing, just a little less straight forward http://www.aspfree.com/c/a/ASP.NET/ASPNET-Custom-Server-Controls-Cute-ToolTip-Control-with-Better-Framework/[^] 1 line of code equals many bugs. So don't write any!! -- modified at 10:11 Monday 13th February, 2006
-
Ok well your right. Oddly enough the list control doesn't register the attributes. So basically what you should do is to create a DIV object with absolute positioning. The using the Addributes.Add and delete you can set it on the "onMouseOver" event. To sum it up 1) create a DIV, name it something like myToolTip and inside create a SPAN element 2) create the javascript function document.getElementByID('myToolTip').getElelmentByTagName('mySpan').innerText = myToolText; 3) then just add an attribute to the control to display Attribute.Add("onMouseOver", "javascript: callMyJavascriptFunction('myToolText'); I add the code inside the protected Render method of the control and out put all the data needed. You can just as easliy put it inside the Page_Load event of the form here's a link that does the same thing, just a little less straight forward http://www.aspfree.com/c/a/ASP.NET/ASPNET-Custom-Server-Controls-Cute-ToolTip-Control-with-Better-Framework/[^] 1 line of code equals many bugs. So don't write any!! -- modified at 10:11 Monday 13th February, 2006
Hi, Thank u for taking the time to read and reply but i am still not getting the tool tip and i request u to help me out I have div tag whose id is d1 the span whose id is s1 and the dropdownlist's whose id is DropDownList1.(where should i place the dropdownlist?) 1.I have added the following code to override public class DropDownList1 : DropDownList { public override void OnSelectedIndexChanged( EventArgs e ) { this.ToolTip = this.SelectedIndex.ToString(); base.OnSelectedIndexChanged( e ); } }. 2. I have added the following in page load d1.Attributes.Add("onmouseover", "javascript:fndisp('myToolText');"); 3.I have used the following code in aspx file but I am not able to get getElementByTagName when i keep the dot. function fndisp(myToolText) { document.getElementByID('d1').getElementByTagName('s1').innerText = myToolText; } Can u pls tell me how to proceed and why i am not getting getElementByTagName when i place the dot after document.getElementByID('d1'). i am also not clear with what myToolText is. Thanks in advance, Sarah -- modified at 8:41 Tuesday 14th February, 2006
-
Hi, Thank u for taking the time to read and reply but i am still not getting the tool tip and i request u to help me out I have div tag whose id is d1 the span whose id is s1 and the dropdownlist's whose id is DropDownList1.(where should i place the dropdownlist?) 1.I have added the following code to override public class DropDownList1 : DropDownList { public override void OnSelectedIndexChanged( EventArgs e ) { this.ToolTip = this.SelectedIndex.ToString(); base.OnSelectedIndexChanged( e ); } }. 2. I have added the following in page load d1.Attributes.Add("onmouseover", "javascript:fndisp('myToolText');"); 3.I have used the following code in aspx file but I am not able to get getElementByTagName when i keep the dot. function fndisp(myToolText) { document.getElementByID('d1').getElementByTagName('s1').innerText = myToolText; } Can u pls tell me how to proceed and why i am not getting getElementByTagName when i place the dot after document.getElementByID('d1'). i am also not clear with what myToolText is. Thanks in advance, Sarah -- modified at 8:41 Tuesday 14th February, 2006
getElementsByTagName -- I left out an 's' put a colon after javascript. this tells HTML that your going to execute javascript. My statements are not free of syntax errors don't worry about overriding the class. For simplicity just use a regular drop down list control. After you get it working you can move it to a render method when you understand what your trying to do. Try that and see if it works. Usually when I try things for the first I keep them really simple like to test we can change the spans inner text:
function setMyJavaCode() { document.getElementByID('d1').getElementsByTagName('s1').innerText = 'HelloWorld'; } then in the body <body onLoad="javascript:setMyJavaCode();">
that will call your script when the page loads and if your span changes to Hello World then you know your code is correct. Then add a var parameter to the function. When you can set it dynamically change it, then have the drop down list call the function. Take baby steps and you'll be there before you know it. MSDN is a great source to see what events, properties, and methods are available for each element. Nick 1 line of code equals many bugs. So don't write any!! -
getElementsByTagName -- I left out an 's' put a colon after javascript. this tells HTML that your going to execute javascript. My statements are not free of syntax errors don't worry about overriding the class. For simplicity just use a regular drop down list control. After you get it working you can move it to a render method when you understand what your trying to do. Try that and see if it works. Usually when I try things for the first I keep them really simple like to test we can change the spans inner text:
function setMyJavaCode() { document.getElementByID('d1').getElementsByTagName('s1').innerText = 'HelloWorld'; } then in the body <body onLoad="javascript:setMyJavaCode();">
that will call your script when the page loads and if your span changes to Hello World then you know your code is correct. Then add a var parameter to the function. When you can set it dynamically change it, then have the drop down list call the function. Take baby steps and you'll be there before you know it. MSDN is a great source to see what events, properties, and methods are available for each element. Nick 1 line of code equals many bugs. So don't write any!!ok , thanks u so much. sarah