0

I have ten TextBoxes:
TextBox1
TextBox2
TextBox3
TextBox4
TextBox5
TextBox6
TextBox7
TextBox8
TextBox9
TextBox10

How can I get the name of the TextBox the user clicks on (mouse) during runtime? It is a asp.net web page and the program is written in vb.net.

Cheers

5
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by adrianSigamoney
-1

In mouse click event of textbox1... till textbox10 do

Dim strName as string=string.emty
strName=textbox1.name
1

You can do like this also

Private Sub TextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick, TextBox2.MouseClick, TextBox3.MouseClick, TextBox4.MouseClick...till textbox10
        Dim strName As String = ""
        Dim text As TextBox = sender
        strName = text.Name
        MsgBox(strName)

    End Sub
0

Thanks for your help. The onClick and Mouse Click events are not available for textboxs. I have imported several references like system.windows.forms, etc. These may work well on a form, however generates issues with web page development.

I have changed to LinkButton. When I click on it, I store an indicator in an invisible label for use later. However n x number of textboxes = alot of coding.

Regards
Adrian

0

>MouseClick cannot be found error is generated.

You have to use JavaScript code to handle those events (Keys, Mouse etc).

0

javaScript Code:

<script language="javascript" type="text/javascript">
        function getTextBoxID() {
            var srcid = window.event || arguments.callee.caller.arguments[0];
            var target = srcid.target || srcid.srcElement;
            document.getElementById('textBoxId').value = target.id;
        }
</script>

page.aspx:

<asp:TextBox ID="TextBox1" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:TextBox ID="TextBox2" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:TextBox ID="TextBox3" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:TextBox ID="TextBox4" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:TextBox ID="TextBox5" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:TextBox ID="TextBox6" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:TextBox ID="TextBox7" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:TextBox ID="TextBox8" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:TextBox ID="TextBox9" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:TextBox ID="TextBox10" runat="server" OnClick="javascript:getTextBoxID();"></asp:TextBox><br />
        <asp:Button ID="btnGetTxtID" runat="server" Text="Button" 
            onclick="btnGetTxtID_Click" />
        <input id="textBoxId" type="hidden" runat="server"  />

Code Behide:

protected void btnGetTxtID_Click(object sender, EventArgs e)
        {
            string id = textBoxId.Value.ToString();
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.