Client-Side Changes to Hidden Field Not Persisted

I've got a bit of Javascript that updates the value of a HiddenField at some point on the client side. I've verified that the script does in fact update the field. The problem comes during postback, instead of the new value being persisted to the viewstate, its value is lost early on in the postback.

 Any ideas?
 

0
forkbeard
7/19/2007 10:13:36 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies
734 Views

Similar Articles

[PageSpeed] 50

To persist the changes to the server, the hidden field needs to have runat="server" property.  Here is a very simple example to demonstrate it works fine.

 

<asp:HiddenField ID="hdnField1" runat="server" />
<input type="button" value="Change Value" onclick="ChangeValue();" id="CheckValue" />
<asp:Button ID="Submit" runat="server" Text="Check Changed Value" />
<script type="text/javascript">
function ChangeValue()
{
document.getElementById("hdnField1").value = "500";
}
</script>

 In the code: (in VB.NET)

If Not IsPostBack Then
            hdnField1.Value = "100"
        End If
        message.Text = hdnField1.Value
 
0
codeasp
7/19/2007 11:29:02 PM
Reply:

Similar Artilces:

Change hidden field value on client side, then retrieve on serverside
I am trying to change a hidden field's value on the client side with Javascript, then retrieve it after postback.The hidden field is inside a user control. The user control's containing page attempts to access the hidden field's value in a click event handler, but the hidden field's value still has the old value.However, by the user control's prerender phase the hidden field does contain the new value.I notice that if I use Request.Form, the same behaviour is exhibited.How can I retrieve the hidden field's new value, without having to wait for the prerender stage. Or alternatively, how can I...

Highlighting web form fields on validation error events (client-side)
Have anybody eventualy did that? This is a nice feature when the web form highlights it's input fields and/or lables for that fields if they are not validated (client-side). Unfortunatly, there is no such build-in functionality in ASP.NET 2.0 validation controls. But i'm quite sure that's it's possible to make on your own, what do you think?Perhaps an additional js script shoud be added on the buttom of the page which will redefine one or more functions of original js code.Any comments, thoughts, suggestions?My LinkedIn Profile - ASP.NET C# Ninja | My News Feeds Turned out that it's quite ...

Passing client side to server side using hidden field
 I have a hidden asp.net text box that is being updated on the client via javascript. I am trying to determine the best way to detect when that hidden field has changed and read the new value on the server. I would like to do this WITHOUT posting back. I have tried using the TextChanged event but that requires blur state to be changed before it gets fired. What would be the best way to do this? Thanks, Justin.  Can you use __doPostBack() to trigger a partial postback at the same time the hidden TextBox is updated, from JavaScript? Encosia - ASP.NET, AJAX, and more.Lates...

change control property from client side and have changes persist on the server
Hi I was wondering if it was possible to change a control's property from the client side with javascript without a post back and have those changes be reflected on the server when a post back occurs. Such as if I had a label and I change it's text property with javascript without a post back and when a post back occurs I can grab those changes on the server e.x. string labelText = label1.Text;  When using input controls (textbox, select etc) then it's definitely possible. But when using labels (which will be rendered as <span> tags) then I'm not sure they ...

Sending array data with hidden input field from client side to server side
I have some values that I'm sending with javascript to the server side code via a hidden input field.  This works great.  However, I want to find an elegant way to split the values up on the server side.  What I have below works, but it doesn't seem like a very clean solution.  Client codevar values = '&approved=1&funded=0&winprob=2'; document.form1.ipHidden.value = values.toString(); Server codeDim strValues As String = ipHidden.Value.ToString() Dim strApproved = strValues.Substring(strValues.IndexOf("approved=") + 9, 1)Dim st...

How to show "Save changes?" warning after client-side changes in a web-application?
We have a complex web application with a main-menu and sub-menu of tab folders; each tab-folder shows a different screen. Suppose the user selected tab folder A, got the A screen and changed a number in a textbox. Now the user clicks the tab folder B and instead of geting the B screen, the user should get a warning "Save your changes?"On "yes" - save the changes in the A screen and show B, on "no" - discard the A changes and show B. How to do this?   Thanks! Persist the values in the TAB A in a variable(say X), depending on yo...

How to Access/Pass Server Side Array Variable at Another Web Form's Client Side
Hi All,I struck up with some intrested senario at my application development...hope some body will guide me or sends me some code snippets....Thanks in advance.Senario is like this.....in A.aspx (using C# .net 2.0 as code behind) I am going to have a array variable basically it is an TWO Dimensional array after populating the values in array I need to redirect/ reload another web form B.aspx, here i need to access the array in B.aspx client side JavaScript.How can I do this...Thanks AgainRaju Dont do a redirect but use server.transfer. That way the previous page will still hold its value, ...

Submitting Web forms fields to sql database by clicking on SUBMIT FORM and sending the form fields to email box
I have a created or designed a form to be stored in a SQL database table and at the same time when a user clicks on SUBMIT button the form fields will automatically goto the visitor email address immediately. Also i have created a database with tables for each of this forms Pls help i have over 10 forms designed but the problem of submitting them to the table database and the user email address is the challenge now.... You ned to familiarise yourself with the basics of database access in ASP.NET.  There are free tutuorials here: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/da...

How to persist client-side changes to a listbox?
I have a listbox to which items are added from the client side. How would I persist these changes so that they are available on server side code?sun21170...

Changing client side cookies in .NET
I have a few cookies in my applicaiton which are created using javascript. Now I can read the cookies no problem. I can create the cookies in .NET and read them in javascript no problem. If the cookie is created in .NET i can modify it's value in .NET no problem. If the cookie is create in javascript I can modify it's value in javascript no problem. What I can't do is change the value of a cookie created in javascript using .NET. I have tried every permutation of Cookies.Add, Cookies.Set, Cookies.Remove using both the response and request objects. I can debug the code and see ...

detecting changes in the fields of a web form
Is there any easy way to detect if there have been changes to a web form's fields. I want to provide the user with an option to save if the fields have changed and don't want to write the checks myself since there are so many of them. thanks in advance, Uval Maybe there is something in IE 6 that I don't know about, but when I did this, I had to write several functions to support an isPageDirty routine. Each page element had to be hooked up to a function that fired on the appropriate event.Richard ok, I solved this problem in a way which is not very intrusive. I'm posting my solut...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Open web page in IE and populate fields on the form from my web form
To the dot net Knights.  Many humble thanks in advance from a dot net surf. We have an vb application that opens multiple instances of IE object, each to different web pages.  It then takes information from the current record in the app, populates fields on each of the web pages, and them submits the forms.  We are then able to look at the resulting web pages and quickly get the info we're looking for.This prevents us from having to manually navigate to each web site, enter the same information and then wait for the page to open.  If there is ...

Persist Client Side Control Property Change
 Hello, I am doubtful that what I am about to as is even possible, but here it goes anyway.  I am using google maps, and when a marker is clicked I need to change the value in a hidden field on the page and force a postback.  This is done client side.  I am using an update panel underneath the map, and am using javascript to click a button inside of the the UpdatePanel to trigger the postback.  On the serverside, I need to be able to access the hidden field value in order to display the correct data in a gridview, which resides in the update panel.  Is ther...

Web resources about - Client-Side Changes to Hidden Field Not Persisted - asp.net.web-forms

Client-side scripting - Wikipedia, the free encyclopedia
... different and changing content depending on user input, environmental conditions (such as the time of day), or other variables. Client-side ...

Senior Search Manager - Client Side!!
... strategy insight for senior IT management - resources to understand and leverage information technology. Senior Search Manager - Client Side ...

Account Manager - Client Side - Previous Agency Experience Welcome!!
Computerworld Australia is the leading source of technology news, analysis and tools for IT decision makers, managers and professionals.

Media Sales Executive - Client Side!!
Technology news and reviews for business and home.

PPC Paid Search Manager - CLIENT SIDE
Defining Technology for Australia's IT Leaders. PPC Paid Search Manager - SEM - **CLIENT SIDE** Sydney CBD Location Client side!! SEM/PPC/Paid ...

How Basecamp Next got to be so damn fast without using much client-side UI
When we started working on Basecamp Next last year, we had much internal debate about whether we should evolve the existing code base or rewrite ...

Seven Tips for Pitching From the Client's Side of the Table
I had a chance to sit on the other side of the pitch table. Here is what I learned.

Client-side coding: How to prevent malicious use?
Applications that run on a user-controlled device cannot be perfectly protected.

The client side
... regarding the professionals you seek to assist. Even better if you possess that understanding yourself, having worked on the client side. I'm ...

Ecommerce traffic being hijacked by client side malware
According to new research 15 to 30 percent of eCommerce site visitors are infected with Client Side Injected Malware (CSIM) that causes them ...

Resources last updated: 1/4/2016 11:47:50 AM