473,382 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

how to make mouse over event in ASP.net

hi.. i am using a textbox1 who contain some text.. and i have another textbox2 where i want to display the text of textbox1 on mouseover of textbox1.... plz suggest me how could it possible without using java script..?plz help?and i am using asp.net 3.5
Feb 10 '09 #1
4 20256
PRR
750 Expert 512MB
The most convenient way is to use JavaScript...
Expand|Select|Wrap|Line Numbers
  1. TextBox1.Attributes.Add("onkeyup", "document.getElementById('TextBox2').value= document.getElementById(this.id).value;");
  2.  
Otherwise you will have to write the code in some server side event ...
Expand|Select|Wrap|Line Numbers
  1. protected void ServerControl_Click(object sender, EventArgs e)
  2.     {
  3.         TextBox2.Text = TextBox1.Text;
  4.     }
  5.  
any reasons for not using JavaScript?
Feb 10 '09 #2
ok thanx.,,,,, i'll try that one..thanx fr help,,, but in 2nd solution how to create server side event .....?i want mouse over event not a click event..
Feb 10 '09 #3
PRR
750 Expert 512MB
@avinash sh
use java scripts... You cant fire server side code for mouse hover or other client side without the help of java script...
Feb 10 '09 #4
Frinavale
9,735 Expert Mod 8TB
@avinash sh
This is all doable client side.
There's no need to make an expensive server side call.

All you have to do is retrieve the text from TextBox1 and display it above TextBox2 (I think you meant this) when the mouse hovers over it right?

Place a Label above your TextBox2 that will be used to display the text.
Labels are rendered as <span>s. Write JavaScript that will retrieve the text from TextBox1 and place that in the inner html of the label (the <span>).

Here's pure HTML/javascript:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function mouseOver()
  5. {
  6.     var theText = document.getElementById("myTextBox1").value;
  7.     document.getElementById("myLabel").innerHTML = theText;
  8.  
  9. }
  10. function mouseOut()
  11. {
  12.      document.getElementById("myLabel").innerHTML = "";
  13. }
  14. </script>
  15. </head>
  16.  
  17. <body>
  18. <input type="text" value="some text in my text box 1" id="myTextBox1" />
  19. <br />
  20. <br />
  21. <br />
  22. <span id="myLabel"></span><br />
  23. <input type="text" value="" id="myTextBox2" onmouseover="mouseOver();" onmouseout="mouseOut();"/>
  24.  
  25.  
  26. </body>
  27. </html>
  28.  
If this were ASP.NET code you'd have to retrieve the ClientID of the TextBox1 control and the ClientID of the Label control. To do this you can use ASP to write the value directly into the script:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function mouseOver()
  5. {
  6.     var theText = document.getElementById("<%=myTextBox1.ClientID%>").value;
  7.     document.getElementById("<%=myLabel.ClientID%>").innerHTML = theText;
  8.  
  9. }
  10. function mouseOut()
  11. {
  12.      document.getElementById("<%=myLabel.ClientID%>").innerHTML = "";
  13. }
  14. </script>
  15. </head>
  16.  
  17. <body>
  18. <asp:TextBox ID="myTextBox1" runat="server" />
  19. <br />
  20. <br />
  21. <br />
  22. <asp:Label id="myLabel" runat="server"></asp:Label><br />
  23. <asp:TextBox ID="myTextBox2" runat="server" onmouseover="mouseOver();" onmouseout="mouseOut();"  />
  24.  
  25.  
  26. </body>
  27. </html>
  28.  

If you wanted to execute server side code for some reason during the mouse over event, then you would have to implement an Ajax Call to a method on the server. You'll have to learn how to use Ajax to do this.
Feb 10 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ganesh | last post by:
hi pals, I like to know ,how to generate a mouse event through the java program .. the user should not need to trigger the mouse event.the program should control the mouse to generate a mouse...
0
by: Bsiang Tan | last post by:
Hi all, I have a few PictureBox in my windows form... The PictureBox mouse event likle MouseLeave work fine.. But the problem occured when I minimize my form into System Tray, and then...
0
by: Bsiang Tan | last post by:
Hi all, I have a few PictureBox in my windows form... The PictureBox mouse event likle MouseLeave work fine.. But the problem occured when I minimize my form into System Tray, and then...
3
by: MrNobody | last post by:
Say I want to do a specific action if the user holds down the CTRL key while clicking something in my UI- how can I determine if this key is currently pressed within the mouse event?
2
by: scott_gui | last post by:
I am creating a Windows application: The mouse event <Double-Button-1> has a conflict when the <Button-1> event also has a binding. Double clicks will first perform the single click action. This...
2
by: Ryan Liu | last post by:
Hi, I need the MouseDown event be trigged everytime when you press mouse in a datagrid (System.Windows.Forms). But seems mouse event will only fire once, and it seems changed to edit mode...
1
by: Ryan Liu | last post by:
Hi, I need the MouseDown event be trigged everytime when you press mouse in a datagrid (System.Windows.Forms). Hi, I need the MouseDown event be trigged everytime when press mouse in a...
0
by: lechatthierry | last post by:
Is it possible to block a mouse event on an Hyperlink with a general script event? This is quite troublesome for me. I am trying to find a way to block the windows shortcut SHIFT + MOUSE LEFT...
1
by: Neko | last post by:
Is it possible to block a mouse event on an Hyperlink with a general script event? This is quite troublesome for me. I am trying to find a way to block the windows shortcut SHIFT + MOUSE LEFT...
3
by: wanwan | last post by:
I made a game with a window form that needs to record the mouse position to an array at 100 samples per second, so I use the mouse move event to do the job. The problem is the mouse move event...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.