0
I need to update the change textbox when the textbox receives customer value, is filled, I use this function inside the textbox receive customer value in the event Textchanged:
protected void txtvalordocliente_TextChanged(object sender, EventArgs e)
{
if (txtvalordocliente.Text == "")
{
txtvalordocliente.Text = "0";
decimal troco = decimal.Parse(txtvalordocliente.Text.Replace("R$", "")) - decimal.Parse(txtvalorareceber.Text.Replace("R$", ""));
txttroco.Text = troco.ToString();
}
else
{
decimal troco = decimal.Parse(txtvalordocliente.Text.Replace("R$", "")) - decimal.Parse(txtvalorareceber.Text.Replace("R$", ""));
txttroco.Text = troco.ToString();
}
}
And here’s my html code, but it either works once in a while or it doesn’t work, I can’t fix it.
<asp:UpdatePanel ID="UpdatePanel12" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label44" runat="server" Text="Forma de Pagamento"></asp:Label>
<br />
<asp:DropDownList ID="cbformapg" runat="server">
<asp:ListItem>DINHEIRO</asp:ListItem>
<asp:ListItem>CHEQUE</asp:ListItem>
<asp:ListItem>CARTÃO</asp:ListItem>
<asp:ListItem>BOLETO</asp:ListItem>
<asp:ListItem>DEPÓSITO</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label46" runat="server" Text="Valor Do Cliente"></asp:Label>
<br />
<asp:TextBox ID="txtvalordocliente" runat="server" onKeyPress="return(MascaraMoeda(this,'.',',',event))" placeholder="R$" AutoPostBack="True" OnTextChanged="txtvalordocliente_TextChanged"></asp:TextBox>
<br />
<asp:Label ID="Label47" runat="server" Text="Valor a Receber"></asp:Label>
<br />
<asp:TextBox ID="txtvalorareceber" runat="server" onKeyPress="return(MascaraMoeda(this,'.',',',event))" placeholder="R$" AutoPostBack="False" OnTextChanged="txtvalorareceber_TextChanged"></asp:TextBox>
<br />
<asp:Label ID="Label48" runat="server" Text="Troco"></asp:Label>
<br />
<asp:TextBox ID="txttroco" runat="server" onKeyPress="return(MascaraMoeda(this,'.',',',event))" placeholder="R$" AutoPostBack="True"></asp:TextBox>
<br />
</ContentTemplate>
</asp:UpdatePanel>
Load event:
if (!IsPostBack)
{
Session["contador"] = 0;
CarregaTaxa();
CarregaContas();
btnReceber.Visible = false;
btnExcluir.Visible = false;
CarregaReceitas();
idconta();
CarregaServicos();
txtObs.InnerText = cbreceita.SelectedItem + "(" + cbplanos.SelectedItem + ")" + " - " + txtPessoa.Text;
txtValorIncluir.Enabled = true;
Valor();
txtVencimentoIncluir.Text = DateTime.Now.ToString("dd/MM/yyyy");
DateTime data = DateTime.Now;
Data.Value = data.ToString();
SqlConnection conexao = clsdb.AbreBanco();
SqlDataAdapter da = new SqlDataAdapter("select c.id,case WHEN s.descricao is null THEN 'VENDA DE PRODUTO'else s.descricao END AS Modalidade, convert(date,c.vencimento,103) as Vencimento,c.Observacao , c.valor_pago, c.valor, quitado, p.nome, p.id from dbo.contas_receber as c left join servicos as s on s.id = c.servico_id left join pessoa as p on p.id = c.pessoa_id where vencimento >= (convert (char(10), getdate(),103)) and vencimento <= (convert (char(10), getdate(),103)) order by vencimento asc", conexao);
ds = new DataSet();
da.Fill(ds, "contas_receber");
GridView1.DataSource = ds.Tables["contas_receber"];
GridView1.DataBind();
cbPesquisa.Text = "Pessoa";
if (cbPesquisa.Text == "Pessoa")
{
txtDataInicial.Visible = false;
txtDataFinal.Visible = false;
txtPesquisa.Visible = true;
}
if (cbPesquisa.Text == "Plano")
{
txtDataInicial.Visible = true;
txtDataFinal.Visible = true;
txtPesquisa.Visible = true;
}
if (cbPesquisa.Text == "Vencimento")
{
txtDataInicial.Visible = true;
txtDataFinal.Visible = true;
txtPesquisa.Visible = false;
}
if (cbPesquisa.Text == "Recebimento")
{
txtDataInicial.Visible = true;
txtDataFinal.Visible = true;
txtPesquisa.Visible = false;
}
GridPessoa();
GridComprador();
CarregaProdutos();
if (cbreceita.SelectedItem.ToString() != "VENDA DE PRODUTOS")
{
idconta();
CarregaServicos();
txtObs.InnerText = cbreceita.SelectedItem + "(" + cbplanos.SelectedItem + ")" + " - " + txtPessoa.Text;
txtValorIncluir.Enabled = true;
Valor();
Button4.Visible = false;
Label22.Visible = true;
cbplanos.Visible = true;
txtValorIncluir.Enabled = true;
Button3.Enabled = true;
}
if (cbreceita.SelectedItem.ToString() == "VENDA DE PRODUTOS")
{
txtObs.InnerText = cbreceita.SelectedItem + "(" + cbplanos.SelectedItem + ")" + " - " + txtPessoa.Text;
cbplanos.Visible = false;
txtValorIncluir.Enabled = false;
Button3.Enabled = false;
Button4.Visible = true;
Label22.Visible = false;
}
UpQuantidade.Text = "1";
txtDescontoAdd.Text = "0,00";
CarregaValorProduto();
SqlConnection conConexao6 = clsdb.AbreBanco();
SqlCommand cmd6 = new SqlCommand("SELECT valor_venda,id FROM produto where nome='" + cbProdutoAdd.SelectedItem + "'", conConexao6);
SqlDataReader dr6 = cmd6.ExecuteReader();
if (dr6.HasRows == true)
{
if (dr6.Read())
{
txtValorAdd.Text = dr6[0].ToString();
txtValorFinalAdd.Text = dr6[0].ToString();
txtidprodutoAdd.Text = (dr6[1].ToString());
}
}
}
Add the code of your entire event and also the page load.
– Aline
I added the event, on the page load, has not related to this code, until I tried to put inside the if (!Ispostback) but it did not work.
– Mariana
Add pageLoad code, because your problem might be there.
– Aline
I added Aline.
– Mariana
Actually Aline, rs now is not even updating, I tried to put updatepanel as always, autopostback as true of all, but no way is working now.
– Mariana
Wait, at what point do you want the value to appear in txttroco? Pq Voce set Autopostback to false in txtvalorareceber..
– Aline
I wanted that when typed in txtvalordoclient txttroco was updated, the field txtvalorareceber, it comes filled automatically.
– Mariana
Hummm, so if you don’t want to give the postback, you’ll have to do with js updating that field.
– Aline
That’s why I use Updatepanel, to update only the textbox, but it’s not working, I use it in other contexts and it works.
– Mariana