|
-
Oct 24th, 2003, 12:43 PM
#1
Thread Starter
Frenzied Member
Calling sub when txtField is changed?
How can I call a sub using visual basic. Net in a web form right after a txtfield is entered/changed? I have tried this but is doesn't do what I wish.
Code:
Private Sub post1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles post1.TextChanged, post1.Unload, post1.DataBinding
If post1.Text <> "-" Then
getZip()
End If
End Sub
-
Oct 24th, 2003, 02:14 PM
#2
Member
these events works at server side so i dont think its a good idea to write a procedure in change event which makes the round trip for each letter. java script is the good way of handling it. it works with change event good.
good luck
-
Oct 26th, 2003, 01:50 PM
#3
Hyperactive Member
That event(TextChanged for server side or onchange for clientside javascript) works differently on a web page than on a windows form; it only fires when the control loses focus, not for every letter. I've used the server side version when I need to do some calculation based on user input that can't wait until all fields are filled in before doing the calc; the server side solution allowed my business rules for that calc to not be published to the client as they would be if i used javascript. Validation can still be stuck on the clientside, really depends on how much you want the client to know. If you don't care, I'd do the client side javascript version cuz the postback for a single field can be annoying to the end user. Anyway, here's how to fire that server side event:
VB Code:
<script language="vb" runat="server">
Protected Sub txtTest_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Write("Text was changed to: <b>")
Response.Write(txtTest.Text)
Response.Write("</b><br/>")
End Sub
</script>
<script for="window" event="onload" language="javascript">
if (document.getElementById("txtTest") != null)
document.getElementById("txtTest").focus();
</script>
<html>
<body>
<form runat="server">
<p>Enter some text and then tab away from the field to fire the event.</p>
<asp:TextBox ID="txtTest" Runat="server" AutoPostBack="True"
OnTextChanged="txtTest_TextChanged"/>
</form>
</body>
</html>
-
Oct 27th, 2003, 02:46 AM
#4
Thread Starter
Frenzied Member
Hi PVB, that's exactly what I needed, thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|