| | |
TextBox.Text changed with js don't keep value on postback
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2007
Posts: 55
Reputation:
Solved Threads: 1
Hi,
I have a website on NET 2.0, there I have a textbox and after I change the text on it with a js function, try to save on the DB (I have to click on a imagebutton to save it), but on the postback the textbox.text property has the previous value.
I need some guidance on how to resolve this.
Here's my code:
JS inserted with a RegisterClientScriptBlock method: <-- This works fine
on PostBack I try to do this:
Thanks
I have a website on NET 2.0, there I have a textbox and after I change the text on it with a js function, try to save on the DB (I have to click on a imagebutton to save it), but on the postback the textbox.text property has the previous value.
I need some guidance on how to resolve this.
Here's my code:
JS inserted with a RegisterClientScriptBlock method: <-- This works fine
ASP.NET Syntax (Toggle Plain Text)
<script type="text/JavaScript"> function Calcular() { if (!(isNaN(parseFloat(document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcPagSaldoPrevioPago').value)) && isNaN(parseFloat(document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcPagPagoActual').value)))) { document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcSaldoPostPago').value = parseFloat(document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcPagSaldoPrevioPago').value) - parseFloat(document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcPagPagoActual').value); } else { document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcSaldoPostPago').value = '0.0';} } function ActualizaMonto() { if (!(isNaN(parseFloat(document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcPagSaldoPrevioPago').value)) && isNaN(parseFloat(document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcPagPagoActual').value)))) { document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcPagSaldoPrevioPago').value = parseFloat(document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcPagMontoTotal').value); } else { document.getElementById('ctl00_cphVentanillaAtencionMaster_txtdcPagMontoTotal').value = '0.0';} } </script>
on PostBack I try to do this:
oPagosBE.btPagActivo = True
oPagosBE.dcPagMontoTotal = Me.txtdcPagMontoTotal.Text
oPagosBE.dcPagPagoActual = Me.txtdcPagPagoActual.Text
oPagosBE.dcPagSaldoPrevioPago = Me.txtdcPagSaldoPrevioPago.Text <--- THIS VALUE POSTBACKS WITH THE INITIAL VALUE (BEFORE JS)
oPagosBE.dtPagFechaRegistro = IIf(IsDate(Me.txtdtPagFechaRegistro.Text.Trim), Me.txtdtPagFechaRegistro.Text.Trim, #1/1/1900#)
oPagosBE.vcPagUsuarioRegistrante = Session.Item("vcUsuCodigo")
bExito = bPagosBL.Insertar(oPagosBE)Thanks
•
•
Join Date: Jan 2006
Posts: 22
Reputation:
Solved Threads: 4
I once had a similar challenge. The TextBox is not aware of the change you made because it is a server control and the change was not made on the server but on the client side.I Corrected the situation by changing my control to an html control. I hope this help.
Emmanuel Balogun
Senior .Net Developer
Precise Financial Systems
Lagos-Nigeria.
Senior .Net Developer
Precise Financial Systems
Lagos-Nigeria.
•
•
Join Date: Jul 2007
Posts: 15
Reputation:
Solved Threads: 1
It can be done,
Please use this form,
From server side,
Please use <%=ServerControlName.ClientID%> everytime you wanna access a server control from client side.
Please use this form,
ASP.NET Syntax (Toggle Plain Text)
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> function setval() { themsg = document.getElementById("<%=txtMessage.ClientID%>"); themsg.value="Hello World!"; } </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="txtMessage" runat="server" Text=""></asp:TextBox> <asp:Button ID="btnSeeMessage" runat="server" Text="see" onclick="SeeMessage" /> </form> <input id="cID" onclick="setval();" type="button" value="Set from client" /> </body> </html>
ASP.NET Syntax (Toggle Plain Text)
protected void SeeMessage(object sender, EventArgs e) { Response.Write(txtMessage.Text); }
Please use <%=ServerControlName.ClientID%> everytime you wanna access a server control from client side.
Last edited by ebookfinder; Aug 9th, 2009 at 3:07 pm.
•
•
Join Date: Aug 2007
Posts: 55
Reputation:
Solved Threads: 1
I used the "Control.ClientID" to reference my control, but no luck...
and I can't use a client side control, because I need to access it in the server also...
I gave up, I know there's a solution out there, but I have no time... I'm on a schedule... Thanks a lot!! to all of you... !!
and I can't use a client side control, because I need to access it in the server also...
I gave up, I know there's a solution out there, but I have no time... I'm on a schedule... Thanks a lot!! to all of you... !!
•
•
•
•
It can be done,
Please use this form,
From server side,ASP.NET Syntax (Toggle Plain Text)
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> function setval() { themsg = document.getElementById("<%=txtMessage.ClientID%>"); themsg.value="Hello World!"; } </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="txtMessage" runat="server" Text=""></asp:TextBox> <asp:Button ID="btnSeeMessage" runat="server" Text="see" onclick="SeeMessage" /> </form> <input id="cID" onclick="setval();" type="button" value="Set from client" /> </body> </html>
ASP.NET Syntax (Toggle Plain Text)
protected void SeeMessage(object sender, EventArgs e) { Response.Write(txtMessage.Text); }
Please use <%=ServerControlName.ClientID%> everytime you wanna access a server control from client side.
![]() |
Similar Threads
- Add value to textbox at runtime (C#)
- c# Changing Textbox.Text from different class (C#)
- textbox text validation (C#)
- text box input (C#)
- Replicating Screen textbox.text to defined printed area (VB.NET)
- textbox.text not showing up (VB.NET)
- dynamic textboxes (ASP.NET)
- separating line by line from textbox with textmode=multiline (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: CreateUserWizard.Password returns empty string
- Next Thread: Runtime Error
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox click commonfunctions compatible confirmationcodegeneration content contenttype courier css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu dynamically edit expose fill flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery listbox login menu microsoft mono mouse mssql multistepregistration news numerical objects opera order panelmasterpagebuttoncontrols radio ratings registration reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers





