newb event attempt.

Q

Qwert

Hello,

two questions about the following code (.aspx file):

Why doesn't the 'Text' property of control 'Label1' get changed in the
function 'SetLabelText()'?
How do I trigger the 'SetLabelText()' function when the mouse moves over the
label control? The line code as below does not function.

Thanks.



<html>
<head>
<script language="VB" runat="server">
Sub SetLabelText()
Label1.Text &= "SetLabelText"
Response.Write ("<br>Hallo")
End Sub
Sub Page_Load(sender As Object, e As EventArgs)
TextBox1.Attributes("onmouseover") = "javascript:alert('Hello!
mouse is over textbox!!')"
Label1.Attributes("onmouseover") = "<% SetLabelText() %>"
End Sub
</script>
</head>
<body>
<h3>Attributes Property of a Web Control</h3>
<form runat="server">
<asp:TextBox id="TextBox1" columns=54 Text="Move mouse over textbox to
trigger onmouseover event." runat="server"/>
<asp:label id="Label1" runat="server" Text="TESTING" />
<% SetLabelText() %>
</form>
</body>
</html>
 
B

Brock Allen

There is a difference between server side and client side events. You're
on the right track for your client side events (with alerts and onmouseover,
etc), but your server side code is in VB.NET. That isn't javascript and it
only runs on the server. It runs on the server a as result of a postback.
So you'd need to either have a button and have a server-side click event
for the button at which time you can set the label's text or you can do this
work in Page_Load which is called for every request to the server. In Page_Load
you can identify a GET vs a POST via the IsPostBack property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top