Updating A Hidden Field Via JavaScript?

Feb 3, 2011

I inherited some JavaScript that I was told to integrate into our ASP.NET site. I thought this would be straightforward but it's turning out to be a bit of a challenge.

The code looks something like this:

<SELECT id="Question1" name="Question" onchange="updateQuestion();">
<OPTION value="notChosen">--Please Select One--</OPTION>
<OPTION value="in">India</OPTION>
<OPTION value="de">Germany</OPTION>
<OPTION value="fr">France</OPTION>
<OPTION value="us">United States</OPTION>
<OPTION value="ch">Switzerland</OPTION>
</SELECT>

The goal is to get the value from this HTML control into ASP.NET, however this control itself is being dynamically generated by another chunk of javascript, so I can't just change this to an asp.net control. My solution was to add the onchange="updateQuestion();" method, this JS will take these SELECT tags and place the values into an ASP.NET control:

function updateSecQ() {
var sQuestion = document.getElementById('<%=sQuestion.ClientID%>');
sQuestion.Value = "";
var questions = document.getElementsByName('Question');
for (question in questions) {
if (questions[question].value != null)
sQuestion.Value += questions[question].value + ",";
}
alert(sQuestion.Value);
}

As you can see, that's looking to update an ASP.NET control:

<asp:HiddenField ID="sQuestion" runat="server" value="" />

This appears to all work, however when I goto the server side on the form submit I see that sQuestion.Value is still = "".

View 4 Replies


Similar Messages:

Gridview Hidden Field - How To Get A Hidden Field Value Using JavaScript

Jan 7, 2010

I have Gridview like this:

<asp:GridView ID="gvPartsSearchResult" runat ="server" CssClass="MRJ_TextGrid">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:RadioButton
ID="rdButton"
runat="server"
AutoPostBack ="true"
onclick="javascript:CheckOtherIsCheckedByGVIDMore()"/>
<asp:HiddenField
ID="hdnFileExtension"
runat="server"
Value ='<%#Bind("FILE_EXTENSION")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

I want to read the hidden field value when the user clicks on the radio button.

View 2 Replies

State Management :: Hidden Field Value In User Control / Make The Hidden Field Save Its Value?

Mar 23, 2011

I have a custom user control which contains a asp hiddenfield object. The value of this hidden field is being set using javascript and I have verified that the value is being set properly. When a postback occurs the new value is not being saved and I cannot access it in my code.

I believe the problem is because the user control is not saved in viewstate and therefore the hidden field value is not saved accross postback. How can I make the hidden field save its value? I tried accessing it from the early page cycles and still no luck.

View 4 Replies

Javascript - Set Hidden Field Value After Postback.

Jul 29, 2010

I have a component that determines a value on a postback event.

protected void Button_Click(object s, EventArgs e)
{
HiddenField.Value = 5;
}

There's more involved in the value of course, but HiddenField is an asp:HiddenField control with runat=server set. I have in my javascript:

var id = $("#<%= HiddenField.ClientID %>").val();

The code in the javascript is set to be run only after the postback has occured (a different client click event) for the purpose of passing the hidden field value via QueryString to another URL (since i can't do a response redirect on postbacks and the client wants it in a different page anyway).

I tried adding:

ScriptManager.RegisterHiddenField(HiddenField, "Value", string.Empty);

To a !Page.IsPostback section of code, but the ID is still not set when the javascript is run.

View 2 Replies

Javascript - Hidden Field Data Lost On Postback

Nov 18, 2010

I am working on an ASP.NET application (well supposed to be deploying it about 3 days ago) and my hidden fields are loosing value when the form gets posted back..

I am using them to store information i write using javascript and on my own machine this works fine but as soon as i deploy it on our server everything else works except these values are lost..

I am using the .NET AJAX control toolkit on the same page and have noticed my calander datepicker also looses the data..

I have checked using firebug and the data is definitely getting post to the server but is getting lost somewhere!

View 1 Replies

Javascript - Getting Null Value Of The Hidden Field At Server Side

Feb 18, 2011

I am calling a Java-script function, in that i am passing the value of hidden field, that hidden field i want to use at server-side, but the value of hidden field is null.

Client Side function

function getDetails()
{
document.forms[0].HdnNode.value=tree_selected_id; //HTML Hidden Field.
str="Cmp_12";
str_array=str.split("_");
var str_array1=str_array[0];
var str_array2=str_array[1];
document.getElementById("<%=HiddenNodeId.ClientId %>").value=str_array1;
document.getElementById("<%=HiddenTreeId.ClientId %>").value=str_array2;
}

Server Side Function

Public Sub InsertNodes(ByVal NodeId As String)
Dim objErrorObj As New ErrorObj
Dim ParentID As String
ParentID = HiddenNodeParent.Value
NodeId = HiddenNodeId.Value
Dim NodeIDTree As String
NodeIDTree = HiddenTreeId.Value
End Sub

View 1 Replies

Web Forms :: Accessing Hidden Field From The User Control On Aspx Using Javascript

May 28, 2010

I have a user control that i have registered to an aspx page. Now from the aspx page, i am trying to access one of the registered usercontrol's hiddenfield value in my aspx page using javacript using the below code:

tst = document.getElementById('control1$hdnField').value;

I looked into the page's trace, and i could see 'control1$hdnField'. Then why i am not getting its value in my aspx page. I have also confirmed that the hidden field by this name exists in the user control and also has a default value set.

View 9 Replies

Web Forms :: Javascript - Set Source File And Assigning Value To A Hidden Field Control

Oct 8, 2010

have a tree view control build dynamically. i want to change color of the selected node from client side. write the script given below. and its work fine.

[Code]....

[Code]....

[Code]....

View 1 Replies

Asp Mvc Jquery Hidden Field

May 12, 2010

the thing is that I have a form with a textbox and a button and a hidden field, now what i want to do is to write something in the textbox ,pass it to the hidden field and then access that thing written in the hidden field in the controller . how can i do that?

View 3 Replies

Hidden Field Vs Viewstate?

Jan 23, 2011

What is the difference when using ::

Hidden field vs View state??

when to use each one ??

which one more secure?? and which is better than in performance?

what are the alternatives?

View 3 Replies

How To Able To Assign A Value To My Hidden Field Control

Mar 4, 2010

how am I be able to assign a value to my hidden field control? I have this web service that returns member's ID and name (e.g. 0001-John dela Vega). In order for me to search for a member, I'm using an autocomplete extender, now, if in case that I found the member I'd like to assign its member id to a hidden field. I ask this because I'd like to change the way my web service return data so instead of displaying the member's id and name at the same, I'll just show its member name.

View 1 Replies

The Hidden Field Still Carries The Old Value On The First Postback

Nov 23, 2010

i have a javascript function written like this

[code].....

Now this is working fine but , lets say i have 10 textboxes, if i change the value one the first textbox to be the same as the second textbox , it means it is a duplicate, now the problem here is that the value of the hidden field does not get updated immidiately , you have to click twice to get the real value.

View 1 Replies

VS 2008 Write The Value To The Hidden Field Thru JS?

Mar 14, 2010

wnat to set the HIDDEB FIELD VALUE THRU JS. But I am gettin the error,can anyboy help me out!

Code:
<input id="HiddenField1" type="hidden" value="" runat="server" />

Code:
var _textbox1= document.getElementById('<%= textbox1.ClientID %>');
document.getElementById('HiddenField1').value = _textbox1.value;
alert(document.getElementById('HiddenField1').value);
ERROR(IMAGE ATTACHED)

View 2 Replies

Hidden Field Value Lost On PostBack?

Mar 12, 2010

I have a hiddenfield, which I want to save the scroll position of asp.panel scrollbar during postback, and when during postback this value is called back to set the scroll position.

Using javascript I can grab the value from the scrollbar, and assign it to the hidden field, but when I post the page back the value has gone.

Here is my code snippet:
<script type="text/javascript" language="javascript">
function SetScroll(val) {
[code].....Am I missing something? How do I keep the value during post back?

View 27 Replies

Dynamic Hidden Field After A Postback

Sep 18, 2010

you save data into a dynamic hidden field ,which is created dynamically during the handling of some postback event.what is the best way to retrieve it from this field upon a postback, (besides searching the request for the key of this hidden field and then retrieving the corresponding value as in the code below)?

protected void Button2_Click(object sender, EventArgs e)
{
bool found = false;
for (int i=0; i<this.Request.Form.Keys.Count; i++)

[code].....

View 1 Replies

MVC :: How To Keep A Hidden Field Populated On Validation

Jan 31, 2011

I have a form in MVC3 that includes a check box to copy data if it is the same as a previous form. If the checkbox is checked, it populates the text box with the content from the hidden field. Here's a sample to illustrate what I'm doing:

[Code]....

When the box is checked, it calls FillInfo(), which uses DHTML to fill the TextBox called "ThisInfo" with the value of the hidden field "DefaultInfo."

Here's the problem: if the form fails validation (e.g. "ThisInfo" is a required field and is left blank), the hidden "DefaultInfo" box is getting cleared out -- which I DON'T want it to do. As a result, when the checkbox is clicked, it is copying empty data into the "ThisInfo" field.

View 8 Replies

Hidden Field Value Lost When Postback?

Feb 4, 2010

I have a problem

<script language="javascript" type="text/javascript">

View 2 Replies

How To Fill Hidden Field With Jquery

Jan 26, 2010

im trying this format:

$("#<%= hfWidth.UniqueID %>").val($("#drag").attr("offsetWidth"));

to fill the hidden field with client-side values

but when I do postback, the values doesn't seem to be saved.

View 2 Replies

C# - Accessing Hidden Field Value From A Different Webpage?

Mar 30, 2011

I have stored a string value in a hidden field of a page. How to access it from a different webpage?

View 4 Replies

Checking Hidden Field Is Empty Or Not?

Aug 13, 2010

i have a

<asp:HiddenField runat="server" ID="ListTwoHiddenField" />

i have some programming aspect how can i check whether hidden field is empty or not i mean i want to check that ListTwiHiddenField.items.cout==0 or empty how can i check this

View 2 Replies

Store Viewstate Other Than In Hidden Field

Jan 30, 2010

can we store viewstate other than in hidden field in asp.net

View 2 Replies

To Set Value For A Hidden Field Through Ajax In .cs Page

Jan 27, 2011

(using Ajax in the backhand) I am trying to set a value for a hidden field, when an id is changed. I am getting object reference not set error.

As of know i return the string value through callback and got it done in the front-hand.

Is there anyway that i can set the value in the code-behind when using Ajax methods.

View 3 Replies

Web Forms :: Value Of A Hidden Field Onblur?

Dec 23, 2010

I am trying to set the value of a hidden field onblur. I add the blur attribute programatically on page load. When the user moves off the control the blur event fires the following javascript.

function getFocus()
{
var obj=document.activeElement;
alert(obj.id);
[code]...

View 11 Replies

C# - Cant Hide The VIEWSTATE Hidden Field?

Jan 20, 2010

I have to hide the VIEWSTATE and EVENTVALIDATION hidden fields on my ASP.net page at RUN time.I managed to remove the EVENTVALIDATION like so.............

<%@ Page enableEventValidation="false" EnableViewState="false" %>

But the VIEWSTATE is still there and I cant get rid of it and I need to. (hard to explain why)Is there another way of getting rid of it?

View 5 Replies

JQuery :: Hidden Field Not Retaining Its Value?

Dec 30, 2010

I'm trying to use jQuery to disable an ASP.Net button control and set the flag in a hidden input field. However, the value does not seem to be staying, for some reason. I am new to jQuery, so I'm having a hard time trouble-shooting this:

[Code]....

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved