protected void currency_txt_TextChanged(object sender, EventArgs e)
    {
        amountSymbol.Text = currency_txt.Text;
    }

I'm trying to change a label according to a TextBox, without a button that has to be pressed?

Recommended Answers

All 3 Replies

Set True value to AutoPostback property of TextBox1. TextChanged event will be raised when a control leaves the focus.

protected void currency_txt_TextChanged(object sender, EventArgs e)
    {
        amountSymbol.Text = currency_txt.Text;
    }

I'm trying to change a label according to a TextBox, without a button that has to be pressed?

you can use onkeypress event of javascript
Like
<asp:Textbox onkeypress="WriteName(this.id);" id="txtT" runat="server">
<asp:Textbox id="txtTest" runat="server">

function WriteName(id)
{
document.getElementById('<% = txtTest.ClientID %>').value=document.getElementById('<% = txtT.ClientID %>').value;
}

textchanged event when occur when you write text after you focus next control that time occur if no text changed that event not fire on server side. you can use this java script

i think this help.

Hi chiragsathit,

The code works exactly as I want it. I tested your code on a sepearte page and it works. On my page it does not do anything.

<script type="text/javascript">
function WriteName(id)
{
    document.getElementById('<% = amountSymbol.ClientID %>').value = 
    document.getElementById('<% = currency_txt.ClientID %>').value;
}
</script>

<table>
<tr>
            <td>Currency (eg R, US$, etc)</td>
            <td><asp:TextBox onkeypress="WriteName(id);" ID="currency_txt" runat="server" Width="275px" Text="R"/></td>
            <td>
            </td>
        </tr>
        
        <tr>
            <td><asp:TextBox ID="amountSymbol" runat="server" /></td>
        </tr>
<table>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.