Vladut Vladut - 7 months ago 16
Vb.net Question

How do i give a value a TextBox create dynamically when i click and doubleClick? vb.net

I have text box create like that:

Dim Result1 As New TextBox
Result1.ID = "BOX_Result" & a & "_" & i


I want when i click on that textbox to write "OK" and when i double click in cell to put NOT/OK

Important! The TextBox is created Dynamically if i try Result.Click doesn't work, get ne that error: "Result1.Click display error: "Click is not an event of 'System.Web.UI.WebControls.TextBox' "

I try like that but doesn't work:


AddHandler Result1.Click, AddressOf Me.Result1_Click


Private Sub Result1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
Result1.Text = "OK"
End Sub


I want when a person click on that textbox created dynamically but doesn't work click. Thanks for help

Answer

You can add these lines to your TextBox definition:

Result1.Attributes.Add("onclick", "this.value = 'OK';")
Result1.Attributes.Add("ondblclick", "this.value = 'NOT/OK';")

In this code, the text "NOT/OK" is displayed when the user double-clicks in the TextBox. In your question, you talk about a double-click "in cell". If that "cell" is not the TextBox, please give some indication of what kind of control it is.

Comments