Get values set by javascript to .net enabled textbox

I have a bit of javasript that writes a value to a text box.  The text box is read only.

Textbox code:
<input type="text" id="txtColor1" runat="server" readonly="readonly" size="6" />

Snippet from javascript function
colorBox = document.getElementById('<%= txtColor1.ClientID %>');
colorBox.value = colorCode;

Code behind:
string color1 = txtColor1.Value

Whenever I attempt to get the value out of the text box after it has been changed by the javascript, it always reverts back to the old data and not the new.

Anyone have an idea of what may be causing this?

thanks ^.^

11/29/2007 7:57:40 PM 24353 articles. 2 followers. Follow

11 Replies

Similar Articles

[PageSpeed] 52

It's an issue with order of operations between when your javascript fires and when the page does a postback. Can you lay out the sequence of events for when/how your javascript gets fired and what triggers your postback?



11/29/2007 8:45:04 PM

I'll give it a shot of what I believe it does in the order of operation: 

1. Page loads and fills in the information

2. I use the javascript to fill in the new values after selecting a new choice.  Setting the new value seems to works just fine as the value is put into the box.

3. Click the save button (.net button) to save the changes.  This does the post back.

All other information is saved but not the settings done with the javascript.


11/29/2007 10:18:52 PM


its not due to the order of operations....

the values assigned to controls except hidden filed will be cleared at the time of postback. This is problem. if you want maintain the values, you need to save the values in hidden controls or recompute the value at server side....

Software Engineer.
11/30/2007 4:39:24 AM

This is good to know and you were right about it having to be in hidden fields.  As soon as I did that the values where being picked up on the post back.  Also, they had to be .net hidden field controls and just not HTML control with the runat on it.

But, if I have more than 3 hidden fields the values stop being picked up.  Less and 3 and it is fine.  I have 7 items.

Anyone have an idea of what may be causing this?


11/30/2007 5:29:36 PM


its not like that... you can have how many controls you need...

there is something wrong. please post your code... 

Software Engineer.
12/1/2007 4:52:01 AM

You could also just make your TextBox an ASP:TextBox and it would retain it's value through PostBacks.



12/2/2007 1:56:00 PM

Hi NC,

is it possible to maintain the values assigned by JS for asp:Textbox during the postback?....


Software Engineer.
12/3/2007 3:58:24 AM

I'm not at work so I can't post the code but I'll do it when I get into the office.  What sort of code are you looking for other than the initial post?  It outlines everything I'm doing.  I also forgot to mention that after experimenting a bit I discovered that it will pick up the new value regardless if it is a hidden field or textbox as long as I don't have more than 3 fields.  Anyway, I'll get the code posted when I get into the office.

Stay tuned. :)

12/3/2007 5:02:07 AM

I don't understand the 3 fields part. I have had many more than 3 fields with no problems. Maybe you should post some if your code.


12/3/2007 12:45:53 PM

I found the problem and was able to solve it.  It turns out it, it was the script that was being called by the scriptmanager for a different part.  It was preventing the information from being picked up correctly.  The cause was the scriptmanager was only calling 1 function instead of 2 how intended.  It was dropping the second call.  After a bit of modification to the process of things, it worked great.  Therefore, it was an order of things or something like that.


12/3/2007 8:58:33 PM

For your future information, ScriptManager does not call the script, it just inserts it into the rendered page.


12/4/2007 1:03:39 PM

Similar Artilces:

Getting Value from Client-side InputBox to .net variable
hi, im doing a login page for our timekeeping. Since there's no msgbox available on, im doing it dynamically via javascript. How do i Get the value frm a dynamically written javascript (such as inputbox) to a .net variable? here's the logic of my program, user logs in hits the button and sub-routine Login will be fired, if user is late -- call Check_Late Sub, this is whre the client-side script was built -- then after that i wanted to be able to get the value from an inputbox. '// if button login clicked Sub Login(Sender As Object, E As EventArgs) .......

how to get value from client side script Prompt window to a session var in .net
hi guyz, i hav a problem with getting a value from a client-side inputbox to a session var in .net. is this possible? however, when i click submit button this is the code that's triggered. dim sb as New System.Text.StringBuilder sb.append("<script language=" & """" & "vbscript" & """" & ">") sb.append(vbcrlf) sb.append(vbcrlf) sb.append("do while xLate =" & """" & """") sb.append(vbcrlf) '//prompt window, val...

textbox value set on client side, is not visible on server side or, on the source of the page.
hi, I have a textbox on my webform. the first time I load my page I fill this textbox with  "name" on the server side. once the page is loaded I set the value of the textbox to "thisIsme" with client side code. I even see a different text in the texbox. client side:document.all('txtnameInput').value =  'thisIsme'; server side:Me.txtnaam.Text 'is stil "name" and not "thisIsme" Why is this happening? on the webpage I see the text "thisIsme", but when I look at the source of the webpage I still see the old value in it. it's very odd... I am NOT setting the value back to "name...

Get textbox value in client side
My problem is that in my ascx file i have a textbox & a input buttom with a javascript function that will validate the textbox: .... <script lang="javascript"> function Test() { if (document.all.txt1.value == "") { alert(); return; } } </script> .... <asp:textbox id="txt1" runat="Server"></textbox> <input type=button id="cmd1" onclick="javascript:Test();" value="Add"> .... But the function don't work, because the textbox control isn't...

How can I set client side values as server side values?
Hi, Can anyone tell me how I can get client side values such as document.referrer, navigator.appName etc... into server side scripts? There are some client side values I'd like to set as session vars and insert into the db? How do I go about this? Thanks for any pointers Davlon PS (I'm using powersite Pass them as page parameters, e.g., http://myserver/myurl?document.referrer=whatever&navigator.appName=yadayada Then, in your server-side script, just loop through the document.value array and get these values. -- pbm_hopethishelps, Roy Kie...

How to get TextBox value that was set by JavaScript
Hi, I used a JavaScript to set a TextBox value.  This works ok, it displays the correct value when the page is rendered.  But when I try to access the TextBox value using the server side code, it does not read the new value.  (I'm assuming it is because the JavaScript code is not actually adding the Text property to the rendered HTML) Here is my test code, does anyone have any ideas? protected override void OnLoad(EventArgs e) { base.OnLoad(e); TextBox tb = new TextBox(); tb.ID = "TestTextBox"; tb.Visible = true; tb.Text = "...

.Net varible into client side JavaScript
I'm need to get a variable from my web app and place its value in a JavaScript. I tried doing this with a Label but I get the HTML included. I don't think I can use the <%# %> from classic ASP? Anyone have any ideas on how they would approach this problem? tbone_stl wrote:Anyone have any ideas on how they would approach this problem? Hi, and welcome to the ASP.NET forums. It's possible to pass a variable to a javascript function. I created a small coding snippet: <%@ Page Language="C#" %>   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http...

how to get javascript value in pageload
Detect acrobat reader installed in client machine. I have to check this in page load. I have hidden field in .aspx to get the return value.  I had used page.registerstartupscript to execute javascript. I can execute the script but i can't retrieve the return value. I can get the value only by using  _doPostBack("hidAcrobat","1"); I need the retrieve the value without page refresh.  Can you please suggest regarding the issue. Thanks, Karnan            declare your hidAcrobat hidden variable in aspx file like b...

Getting Textbox Watermark Text in client side javascript
Can somebody tell me how I can go about grabbing the Text value of a TextBoxWatermark control from client side javascript?  I need to make a comparison/validation if a text box has been filled out (non-blank) and of course the watermark fills in the text value of the text box when grabbing the property (of the text box) per javascript? So, I need to somehow grab the text from the watermark in javascript and then compare to the text box contents to see if the text in the textbox is the water mark text or not.  Any information would be greatly appreciated.  Thanks!  Th...

Get label value on server side set by javascript
 HelloHow are all here.I have set the label text using javascriptdocument.getElementById("lblEmail").innerHTML = Login;Now when I try to get value (i.e. Text), by lblEmail.Text on ASP.Net server page, then the label shows no value or text. i.e. it is empty. why this is happening? how can I get value on Form set by Javascript?regards change in coding document.getElementById("lblEmail").value= "Hello World";   Please remember to click "Mark as Answer" on the post that helps you. This can be beneficial to other community members reading th...

How to use client-side script(javascript) in .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script>  objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ......  }    szUrl = &...

.net validators + client-side javascript validation, EnableEventValidation=false
Scenario: 1. I have a DropDownList, with 2 listitems in the .aspx. appenddatabound=true and it is tied to a datasource (via datasourceid), autopostback=false, onchange=checkIfAddNew(this) [this is the client side onchange event]The second option on this dropdown is "Add New", and the checkIfAddNew function pops up a new window and when it returns, it adds the newly created option to the dropdown. In order for this to happen without getting mad, EnableEventValidation has to be set to false in the Page directive. In addition to this dropdownlist, there is a RequiredFieldValidator...

Get the Dropdownlist text and value using Javascript from client side
Hi, I am encountering a problem about how to get the Dropdownlist text and value using Javascript from client side. I am using C# in Visual Studio 2005 and Javasript . The example codes are like: ( In this example code, I would like to access the text and value of the DropDownListReports in the run() function of Javascript. How can I do that? Any ideas? Thanks a lot. ) protected void Page_Load(object sender, EventArgs e) {              if (!Page.IsPostBack)            &nb...

Perform JavaScript Client Side Confirmation from a VB.NET DataGrid
Hi, I when I delete an item from the database through a Datagrid I want to get a messagebox popingup to give me the choise to Confirm case I clicked the wrong item....the way it works now it just deletes it....can any one help me with an Example I have no Idea how to do this...I found an article in C# but it didnt help me at all. here is my source code <asp:DataGrid ID="dgCustList" Runat="server" AutoGenerateColumns="False" DataKeyField="id" AlternatingItemStyle-BackColor="#F6F6F6" HeaderStyle-BackColor="#C4B58E" CellSpacing="0" CellPadding="2" GridLines="Vertical" Width="100%"...

Web resources about - Get values set by javascript to .net enabled textbox -

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
... editor - report abuse/spam - help the entire directory only in Tools/Obfuscators Description Top : Computers : Programming : Languages : JavaScript ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing ...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken .… ...

Resources last updated: 2/5/2016 1:45:39 AM