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!

Leave event on TextBox

Status
Not open for further replies.

guttaboys

Programmer
Oct 28, 2003
17
NO
Hi

I would like some code to run when the user exits a textbox control, like the leave event when using winforms.

Is there a way to do this, and if, how?

Would like to recalculate a price when user enters/change the value in the textbox.

Thomas
 
You'd just have a javascript function fire on the onblur event.

In the code-behind you'd set it like:

txtMyTextBox.Attributes.Add( "onblur", "myFunction();" );

The function can be hard-coded into the page (.aspx file), or registered with Page.RegisterClientScriptBlock().

If you're not worried about the performance hit of the PostBack, you may also assign a server-side event handler to the control and set the TextBoxes AutoPostBack property to true.
 
just to append to boulders post...

this is inside a template column, hence the findcontrols.
If not in datagrid, you can just do cost=myText.Text
Code:
<asp:TextBox id=myText runat=server width=50 onTextChanged=calcTotal AutoPostBack=True />

...

in script or codebehind...

    Sub calcTotal(sender As Object, e As EventArgs) Handles calcPrice.Click
    	Dim cost, ship, tax, taxp As Double
    	cost = (CType(singlePO.items(0).FindControl("poCostTxt"), TextBox)).Text
    	If CType(singlePO.items(0).FindControl("poShipTxt"), TextBox).Text = "" Then
    		CType(singlePO.items(0).FindControl("poShipTxt"), TextBox).Text = FormatCurrency(0)
    	End If
    	ship = (CType(singlePO.items(0).FindControl("poShipTxt"), TextBox)).Text
    	taxp = (CType(singlePO.items(0).FindControl("poTaxPTxt"), TextBox)).Text
    	Dim taxTb As TextBox = (CType(singlePO.items(0).FindControl("poTaxTxt"), TextBox))
    	Dim total As TextBox = (CType(singlePO.items(0).FindControl("poTotalTxt"), TextBox))
    	Dim shipTb As TextBox = (CType(singlePO.items(0).FindControl("poShipTxt"), TextBox))
    	Dim costTb As TextBox = (CType(singlePO.items(0).FindControl("poCostTxt"), TextBox))

    	If (CType(singlePO.items(0).FindControl("poTaxCb"), CheckBox)).Checked Then
    		tax = cost * taxp
    		taxTb.Text = FormatCurrency(tax) 
    		total.text = FormatCurrency(cost + ship + tax)
    		costTb.Text = FormatCurrency(costTb.Text)
    		shipTb.Text = FormatCurrency(shipTb.Text)
    	Else
    		taxtb.text = FormatCurrency(0)
    		total.Text = FormatCurrency(cost + ship)
    		costTb.Text = FormatCurrency(costTb.Text)
    		shipTb.Text = FormatCurrency(shipTb.Text)
    	End If
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top