473,396 Members | 1,998 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,396 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 2489
"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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.