Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click event on a textbox

Status
Not open for further replies.

LouisC4

Programmer
Jul 26, 2003
54
US
Do textbox controls have a click event? If they don't how is it possible to fire up and event when a user clicks on a textbox control or when the controls gets focus? I am working on a web form?

Thanks,

Louis
 
You can do onTextChanged and AutoPostBack=true serverside, but it doesnt seem that would let anyone actually type anything into the textbox. You can use javascript for the focus event, but the textbox would lose focus after the event fired server side, and if you set focus serverside heres an endless loop for you.

Code:
<form runat="server">
    <asp:TextBox ID="txtBoxEvent" runat="server"></asp:TextBox>
    <asp:LinkButton ID="lbClickEvent" runat="server" Text="Yo!" OnClick="launchServerEvent"></asp:LinkButton>
    <br />
    <asp:Label ID="lblMessage" runat="server"></asp:Label>
</form>
Code:
    Sub Page_Load()        
        If Not Page.IsPostBack Then
            txtBoxEvent.Attributes.Add("onfocus", Page.ClientScript.GetPostBackClientHyperlink(lbClickEvent, "", False))
        End If
    End Sub

    Sub launchServerEvent(ByVal sender As Object, ByVal e As EventArgs)
        lblMessage.Text = "I Did it with JavaScript!"
        'Endless loop if you enable below!
        'SetFocus(txtBoxEvent)
    End Sub
 
<asp:TextBox ID="txtBoxEvent" runat="server" AutoPostBack="true" OnTextChanged="otherServerEvent"></asp:TextBox>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top