473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Javascript changes not saved


I'm using Javascript to change a value in an asp:textbox control on an
asp.net page, then submitting the page and persisting the data using c# code.
I can see the value in the textbox change when the Javascript runs, but when
the page is submitted, the c# event code still sees the original value in the
textbox, not the value that was updated by Javascript.
Here’s the javascript code that changes the value:

document.forms[0].txt1.value = calcCigScore();
alert (document.forms[0].txt1.value);

The alert shows me that the value has changed (I can also see it change on
the page).
And here’s the c# code from the SaveRecord event on the aspx page:

mIntake.CigScore = int.Parse(txt1.Text);

When tracing through the code, I see that txt1.Text still equals the value
that was originally loaded into the page.

Is there a reason why .Net doesn’t see the updated value? Anything I can do
to change that?

Thanks

Oct 10 '06 #1
3 2479
"ken s" <ke**@discussions.microsoft.comwrote in message
news:00**********************************@microsof t.com...
Is there a reason why .Net doesn't see the updated value? Anything I can
do
to change that?
I'm willing to bet that you're loading the original value of the record in
your Page_Load method, and have forgotten to wrap it in a if (!IsPostback)
loop...
Oct 10 '06 #2
It turns out that you get strange results if the textbox is set to disabled.
This is a calculated field and I have it disabled so the users can't modify
it. But eventhough I can see the value in the textbox change when I modify
it with Javascript, I still get the old value when I try to process the data
with c# code. It started working properly when I enabled the textbox.

Thanks for your response.

"Mark Rae" wrote:
>
I'm willing to bet that you're loading the original value of the record in
your Page_Load method, and have forgotten to wrap it in a if (!IsPostback)
loop...
Oct 11 '06 #3
"ken s" <ke**@discussions.microsoft.comwrote in message
news:06**********************************@microsof t.com...
It turns out that you get strange results if the textbox is set to
disabled.
This is a calculated field and I have it disabled so the users can't
modify
it. But eventhough I can see the value in the textbox change when I
modify
it with Javascript, I still get the old value when I try to process the
data
with c# code. It started working properly when I enabled the textbox.
Ah right - if you'd said that it was disabled, I'd have known straightaway!

This, ahem, feature of ASP.NET 2 is thankfully very easy to work round.

Don't do this:

<asp:TextBox ID="MyTextBox" runat="server" Enabled="false" />

Do this:

<asp:TextBox ID="MyTextBox" runat="server" />

And in the Page_Load of your code, do this:

MyTextBox.Attributes.Add("disabled", "true");

Same thing with readOnly...
Oct 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
4
by: Assimalyst | last post by:
Hi, I have a AutoPostBack checkbox and need to set a value bSubmitted = true when the checkbox is checked in order to prevent a warning message appearing notifying the user they are navigating...
0
by: ken s | last post by:
I'm using Javascript to change a value in an asp:textbox control on an asp.net page, then submitting the page and persisting the data using c# code. I can see the value in the textbox change when...
1
by: jb5531 | last post by:
Hello everyone! I am trying to implement some code for my website using JavaScript and DOM. The issue I'm having is that I want to change the size of the textarea on blur. This text area changes...
6
by: stormcandi | last post by:
Hello, I know this question has been asked everywhere but I cannot find a solution that will help me. I hope someone here has some ideas. I have 9 TextBoxes in a Repeater Control. A user can...
12
by: AppPad | last post by:
Hello, This is a new website I am involved with, and we are seeking to open up to a shortlist of users. http://apppad.com The basic overview of the service is: - You define Object Type...
1
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post by:
Hi, I have a the following javascript code(see below) within my asp.net page, I would like to be able to set the value of UnSavedChanges within my c# behind code to indicate that changes have been...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.