locked
Visual Studio Form Building RRS feed

  • Question

  • User1852862511 posted

    Hi,

    I am unsure whether this is possible but, I am trying to create a textbox on my Visual Studio form which will gather the values from two other textboxes and join them together. For example textbox1 would have the value 4555 and textbox 2 would have the value 66666, I want textbox 3 to then have the value 455566666.

    Does anyone know a way of doing this?

    Thanks,Smile

    Tuesday, March 18, 2014 7:42 AM

Answers

  • User-760709272 posted
    <form id="form1" runat="server">
        <asp:TextBox ID="txtA" runat="server" /><br />
        <asp:TextBox ID="txtB" runat="server" /><br />
        <asp:TextBox ID="txtC" runat="server" /><br />
            
        <asp:Button ID="ButtonSubmit" runat="server" OnClick="ButtonSubmit_Click" Text="Join on server" /><br />
        <input type="button" value="Join via javascript on client" onclick="return join();"/>
        <script type="text/javascript">
            function join() {
                var txtA = document.getElementById("<%=txtA.ClientID%>");
                var txtB = document.getElementById("<%=txtB.ClientID%>");
                var txtC = document.getElementById("<%=txtC.ClientID%>");
    
                txtC.value = txtA.value + txtB.value;
            }
        </script>
    </form>
    // code behind
    
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        txtC.Text = txtA.Text + txtB.Text;
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 18, 2014 7:54 AM

All replies

  • User-760709272 posted
    <form id="form1" runat="server">
        <asp:TextBox ID="txtA" runat="server" /><br />
        <asp:TextBox ID="txtB" runat="server" /><br />
        <asp:TextBox ID="txtC" runat="server" /><br />
            
        <asp:Button ID="ButtonSubmit" runat="server" OnClick="ButtonSubmit_Click" Text="Join on server" /><br />
        <input type="button" value="Join via javascript on client" onclick="return join();"/>
        <script type="text/javascript">
            function join() {
                var txtA = document.getElementById("<%=txtA.ClientID%>");
                var txtB = document.getElementById("<%=txtB.ClientID%>");
                var txtC = document.getElementById("<%=txtC.ClientID%>");
    
                txtC.value = txtA.value + txtB.value;
            }
        </script>
    </form>
    // code behind
    
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        txtC.Text = txtA.Text + txtB.Text;
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 18, 2014 7:54 AM
  • User1852862511 posted

    Thank you for your help, that works great!! Laughing

    Tuesday, March 18, 2014 8:15 AM