Client side set hidden field value not POSTing back

 hi,

(sorry, I dont have any code snippets to hand as I'm away from the dev machine at the mo)

I have a page which makes two seperate WebServce calls for data. One is via an Ajax call, the other is server side.

The flow is as follows:

1. Ajax Web Service call returns a collection

2. In the js script file, read the PK's of the collection and set
 a hiddenfield with the comma-seperated keys

3. initiate a __doPostBack call from script - target an update panel on the page which then calls the second Web Service

The problem I am experiencing is that after I have made the first call and set the PK's in the hidden field, the postback fires but the hiddenfield doesnt have the ID's, its empty.

Viewstate is on (but have tried turning it off also).

I know that I can pass an arguement in the postback call which works but this is very limiting since it is likely that I will need to send oterh information back to the server for the second call also.

Any help really appreciated, again, sorry I cant provide code at the mo'.

thanks,
dan


frustrated... on so many levels
0
dt_matthews
9/26/2008 6:19:46 PM
asp.net.client-side 24353 articles. 2 followers. Follow

20 Replies
1340 Views

Similar Articles

[PageSpeed] 9

Is your hidden field just plain HTML?  If so, try adding runat="server" to it.

Best regards...


Josh Stodola ← Come check out my blog!
0
JoshStodola
9/26/2008 7:35:44 PM

 hi josh, no, its a server-side hidden-field


frustrated... on so many levels
0
dt_matthews
9/26/2008 10:55:35 PM

I'm going to have to see some code.  I think you must be resetting the hidden field somewhere, because I have done exactly what you've described at least two times in the past, without issues.

Best regards...


Josh Stodola ← Come check out my blog!
0
JoshStodola
9/27/2008 12:04:32 AM

 hi josh,

 

i know its tricky w/out code!

 

just one thing, when you have done this in the past, were you setting the hidden field explicitly via client side javascript - that's what I'm doing, and its being set in the callback from a json web service if that's relevant.

 i will post code on Monday if there's no update before then.

cheers,

dan


frustrated... on so many levels
0
dt_matthews
9/27/2008 11:10:21 AM

0
CoolBond
9/27/2008 11:44:11 AM

CoolBond:

Hi

If you set the visible property of hidden filed to False, It won’t be available for client side,
So instead use the display style property of control to hide the control.


 this.hdnctrl.Visible=true
 this.hdnctrl.Style.Add("display", "none"); 

 

Hope this will helpful for you

Now why would he have to set a hidden element's state to hidden? It is by nature already hidden.

NC...

 

0
NC01
9/27/2008 12:46:01 PM

NC01:

CoolBond:

Hi

If you set the visible property of hidden filed to False, It won’t be available for client side,
So instead use the display style property of control to hide the control.


 this.hdnctrl.Visible=true
 this.hdnctrl.Style.Add("display", "none"); 

 

Hope this will helpful for you

Now why would he have to set a hidden element's state to hidden? It is by nature already hidden.

NC...

 

 you took the words out of my keyboard NC01 ;-)  its a hidden field, setting a visible attrib would be somewhat nonsensical!

frustrated... on so many levels
0
dt_matthews
9/27/2008 2:07:06 PM

I think that some of these people just like to post things Indifferent

NC...

 

0
NC01
9/28/2008 10:15:38 AM

Hi Josh!

 Here's my script code - callback for the web service that I then postback using __doPostBack(

I'll put the markup in the following post to make it a bit less clumsy

 cheers,

dan

==========

 // Callback for the Hotel Search Web Service call
function HotelResults_GetHotelsInViewResponse(results) {

    try
    {

        lblCaption.innerText = "Hotels in the vicinity of " + txtLocation.value;
        hfHotelCodeList.value = '';

        mapControl.removeAllOverlays();

        if (results != null && results.length > 0)
        {
            for (i = 0; i < results.length; i++)
            {
                // build the hotel code list
                hfHotelCodeList.value += results[i].iCode + ',';

                // Add map marker for the hotel
                var pos = new MMLatLon(results[i].sLatitude, results[i].sLongitude);
                var marker = mapControl.createMarker(pos, { 'label': results[i].sDisplayName, 'text': i + 1 });
                var el = document.createElement('h5');
                el.appendChild(document.createTextNode(results[i].sDisplayName));
                marker.setInfoBoxContent(el);

            }
        }

        // set the hiddenfields with the Search params the user entered
        hfDOA.value = txtDateOfArrival.value;
        hfNoOfNights.value = ddlNoOfNights.value;
        hfNoOfRooms.value = ddlNoOfRooms.value;
        hfNoOfPeople.value = ddlNoOfPeople.value;
        hfSingleOccupancy.value = ddlOccupancy.options[ddlOccupancy.selectedIndex].value == "single";

        // fire a postback on the UpdatePanel
        alert('client value is: ' + hfHotelCodeList.value);
        __doPostBack(hfHotelCodeList.id, '');

    }
    catch (ex) {alert(ex);}
}


frustrated... on so many levels
0
dt_matthews
9/29/2008 6:45:03 AM

 Here the page markup...

===========

 

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HotelList.ascx.cs" Inherits="HotelSearchWidget.HotelSearch.Views.HotelList" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="~/HotelSearch/Scripts/HotelList.js" />
    </Scripts>
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="upHotelList" runat="server" UpdateMode="Conditional" EnableViewState="true" >
<ContentTemplate>
    <asp:Label ID="lblCaption" runat="server" />
    <asp:DataList ID="dlHotelList" runat="server" RepeatDirection="Vertical" Width="100%" DataKeyField="Code">
        <ItemTemplate>
            <asp:Table width="100%" ID="tblHotel" runat="server">
            <asp:TableRow ID="Hotel_NameRow" runat="server">
                <asp:TableCell id="Hotel_Code" Visible="true" runat="server"><%# DataBinder.Eval(Container.DataItem, "Code")%></asp:TableCell>
                <asp:TableCell id="Hotel_Name" runat="server"><%# DataBinder.Eval(Container.DataItem, "Name")%></asp:TableCell>
                <asp:TableCell ID="Hotel_PopupContainer" runat="server"></asp:TableCell>
            </asp:TableRow>
            </asp:Table>
        </ItemTemplate>
    </asp:DataList>
    <asp:HiddenField ID="hfClientCode" runat="server" EnableViewState="true"  />
    <asp:HiddenField ID="hfHotelCodeList" runat="server" EnableViewState="true" />
    <asp:HiddenField ID="hfDOA" runat="server" EnableViewState="true"  />
    <asp:HiddenField ID="hfNoOfNights" runat="server" EnableViewState="true"  />
    <asp:HiddenField ID="hfNoOfRooms" runat="server" EnableViewState="true"  />
    <asp:HiddenField ID="hfNoOfPeople" runat="server" EnableViewState="true"  />
    <asp:HiddenField ID="hfSingleOccupancy" runat="server" EnableViewState="true"  />
    <asp:HiddenField ID="hfSearchResults" runat="server" EnableViewState="true" />

</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress runat="server" ID="upProg">
<ProgressTemplate>
    <img src="../images/NONE_spinner.gif" alt="Please wait animation" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Panel ID="pnlHotelDetails" runat="server">
<div id="theDetails">
</div>
</asp:Panel>

<script type="text/javascript">

    dlHotelList = document.getElementById('<%=dlHotelList.ClientID%>');
    lblCaption = document.getElementById('<%=lblCaption.ClientID %>');
    upHotelList = document.getElementById('<%=upHotelList.ClientID%>');
    hfClientCode = document.getElementById('<%=hfClientCode.ClientID%>');
    hfHotelCodeList = document.getElementById('<%=hfHotelCodeList.ClientID%>');
    hfDOA = document.getElementById('<%=hfDOA.ClientID%>');
    hfNoOfNights = document.getElementById('<%=hfNoOfNights.ClientID%>');
    hfNoOfRooms = document.getElementById('<%=hfNoOfRooms.ClientID%>');
    hfNoOfPeople = document.getElementById('<%=hfNoOfPeople.ClientID%>');
    hfSingleOccupancy = document.getElementById('<%=hfSingleOccupancy.ClientID%>');
    hfSearchResults = document.getElementById('<%=hfSearchResults.ClientID%>');
   
</script>


frustrated... on so many levels
0
dt_matthews
9/29/2008 6:46:15 AM

 anyone?

 cheers,
dan


frustrated... on so many levels
0
dt_matthews
10/1/2008 9:34:33 PM

Sorry, I don't actually know the answer but, well, what happens when you step through using the javascript debugger? You would then be able to see the values being set in the hidden field, and when and if those values change.

Pls use the debugger, it's your friend, the days of "alert" style javascript debugging are thankfully over.

I also notice that you are trying to grab values like "results[i].ICode" and "sString" - are you sure these are public fields, did they get serialized OK? Again the debugger will tell you all.

0
VR2
10/2/2008 8:43:37 AM

Hi

Thanks for you reply. Totally agree re the debugger and alerts, that was just as a quick check when I was trying various things.

The fields are serializing ok.

The values are set fine in the hidden field in the script (debugger displays the changed value), the problem is that the user control which I force a postback to does not pick up the changed values...

If you think of anyhting I'm all ears!

 Cheers,
dan


frustrated... on so many levels
0
dt_matthews
10/2/2008 9:40:41 AM

Hi,

 Here is another way to check for those values...

Just check once with Source of your page (Right Click --> View Source).. Make sure you are getting source line for all of your hidden fields. If you are not getting those lines, there might be some problem in hidden field generation.

 If you can see source lines for your hidden fields then notice what ID is it generating.

If you will check for those hidden fields then you might get IDs of those hidden fields like 'upHotelList_hfClientCode'.. etc. Just copy prefix from there ('upHotelList_') so that you can use this prefix at your code. Don't worry.. this will alway make that same prefix unless you have another level in your page (like for master page or user control).

 Now you can update your code like this and check..

<script type="text/javascript">
  var idPrefix='upHotelList_'
    dlHotelList = document.getElementById(idPrefix+ 'dlHotelList');
   ....
   ....
   .... 
</script>

Hope this works... If not, let me know.. We have few more other ways to do so.

Cheers Smile


Cheers,
Sunny
0
sunny_jags
10/2/2008 10:40:08 AM

I noticed in your JavaScript that you have a lot of this type of thing: hfNoOfNights.value = ddlNoOfNights.value; That will not generally work. Try:

document.getElementById('<%= hfNoOfNights.ClientID %>').value = document.getElementById('<%= ddlNoOfNights.ClientID %>').value;

NC...

0
NC01
10/2/2008 1:49:00 PM

 thanks for that but i am declaring the hidden field variables in another script file which the scipt manager has a reference to. The ClientID is correctly injected to the declarations so they do have a valid pointer to the HF's...

 the values are getting set in the script correctly, they just seem to get lost when posted!?!?!?

I have noticed when I step thru' the js script to check values, I do get a blue dot in the left-hand column (by the breakpoint margin) which when you hover over says the thread or process has changed since the last step. might this be the problem (i,e, getting posted on a different thread???) that said, the __EVENT ARGUEMENT of my postback DOES get sent ok...

any thoughts much appreciated, very frustrated with this!

ta,

dan


frustrated... on so many levels
0
dt_matthews
10/2/2008 5:32:59 PM

Good luck debugging that one. Generally the way that I create JavaScript is to write it directly into the page, get everything working correctly, then export it to include files.

You might want to just download Firebug for JavaScript debugging purposes:

IE: http://getfirebug.com/lite.html
http://getfirebug.com/errors.html

NC...

 

0
NC01
10/2/2008 6:02:28 PM

 Hi experts,

      Just look The hidden field have the Visible attribute. It can be changeable. In that aspect only I answered for the post.I didnt see what is actually happening for him, just a guess. I'm not here without any work. So  please avoid such a answers that hurt others.

<asp:HiddenField ID="HiddenField1" runat="server" Visible="False" />

I didn't expect such an answer from a  MVP of this forum.

so Good Bye.

0
CoolBond
10/3/2008 6:15:18 AM

CoolBond:

 Hi experts,

      Just look The hidden field have the Visible attribute. It can be changeable. In that aspect only I answered for the post.I didnt see what is actually happening for him, just a guess. I'm not here without any work. So  please avoid such a answers that hurt others.

<asp:HiddenField ID="HiddenField1" runat="server" Visible="False" />

I didn't expect such an answer from a  MVP of this forum.

so Good Bye.

I don't see how it could "hurt others" to explain a confusing post, and I still do not understand why anyone would set the Visible property to false on a hidden element. If I hurt your feelings, I apologize, but I just thought that explanation was needed.

NC...

 

0
NC01
10/3/2008 11:57:13 AM

 just awnted to update this with the cause / solution to this problem.

thanks to the tech lead on this project (thanks Chris if you see this!) the problem occurs when the postback is to an update panel (rather than a full postback). the fix is to force an update to the reference of teh hidden field using $get([controlid) . This ensures that the HF refererence is to the updated control rather than keeping a reference to the 'stale' version.

hope that is comprehensible to anyone interested / having a simlar problem.

cheers,
dan


frustrated... on so many levels
0
dt_matthews
10/6/2008 8:58:26 PM
Reply:

Similar Artilces:

Hidden field client side value lost on post back
Hi, I have a checkbox list , two text box , with link to javascript calendars and two hidden fields. The checkbox list contains years with start and end date in text part and the two textboxes are From and To date. Initially when the page is loaded the first year in the list is checked then the hidden field for start and end date is set at server side. After that on client side onload we run a javascript that picks up the date from hidden fields and set them on the two dates textboxex respectively in client locale. No when i change the checkbox check the repect date in text part of the ...

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 7.1.0.300) 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...

Hidden Field that is set on server side...not getting the last updated value from client?
Hi, I have a hidden field that tracks errors in my server side asp.net 2.0 code.  However, when I set the value to an error (from it's default value "NotSet") in the server side code and then when trying to access that Hidden Variable from the client the value is still set to the default value, "NotSet" instead of the error information. Any ideas as to what is going on here? Thanks in advance!   Server Side....  catch (Exception er) { Errors.Value = er.Message; o o o } Client Side.... function getErrors() { var cho = document.getElementById('<%=Errors.ClientID...

Using hidden field to store value then calling that value from client side
I have three tabs (1,2,3) on my main page each tab contains a datagrid... when a user select a tab then leaves the main page and returns to that main page(without exiting browser) I need for the page to open with the tab last selected by that user so that they can pick up where they left off. No one can seem to help me with this issue.... My javascript (client side) code function is as follows: <asp:HiddenField ID="hdnNewPanel" runat="server" /> <script language="javascript" type="text/javascript"> &nb...

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...

Getting hidden variable value from server side in client side
hi,        I am struck in problem. I have a hidden field in my form and i am setting some value in that.         Now i wnt to use this value from client side but i m not able to retrieve it. All i am getting there is an object.         I feel the hidden field is not able to hold that value.         <input type="hidden" id="hdnVar" runat="server" />         in code behind      ...

problem: client side validation posting back server side in firefox only
Hi I have validation controls and I only want them to validate via client side. It works in IE. But in firefox it does validate client side, however it immediately post backs server side. How can I prevent this?? I have a login control and it works fine there. Only problem it occurs is inside a createuserwizard. I have sumary validation with js pop up. Using asp.net 3.5. Before trying to solve the actual problem, please implement server side validation. Consider it a manditory part of validation because: - The user may have a browser not supported by the client-side scripts - T...

client-side and server-side validation reducing post-backs question
For my page I was using server-side validation. In order to reduce post-backs I decided to implement client-side validation -- do the same validation as server (but keep server-side for security reasons). I could not find the answer to this easily -- Does my client-side validation stop post-backs? I've noticed that having one client-side validation does not stop the other server-validations from doing a post-back. Currently I have 5 CustomValidators, all with ClientValidationFunction and OnServerValidate set. When the client script sets args.isValid as false, does it stop the postback fr...

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...

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...

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...

Client Side values to Server Side
What is the best way to transfer Client Side values to the Server side? For example I have a variable "var1" in javascript. var1 = "sample"; How can I acquire this value in the server side?  What is the best approach for this?  Barry to send the value to the server during a postback, you need to place the value in an input control.  You could consider using a hidden textbox for that purpose.Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/ In the JavaScrip...

Client-side values to server-side ?
Hi! My previous query is attached below: I have implemented the below mentioned implementation . 'listbox1' on 'webform1' shows all the values from 'webform2'. I have implemented it using javascript. I would like to know that to implement validation on 'webform1', I would require the values of 'listbox1' ,which are on the client-side , to move to the server-side . I think sending a querystring will be fine but how to implement it using javascript and code-behind(C#)? Your suggestion will be appreciated. Thanks and regards, ap.       My previous query: " I am stuck wi...

The value set to controls at client side donot persist for each page load, else it is again set to the default value...??
 I am trying to set date to the textbox field using javascript (Client side), the function is as follows. function From_calendarPicker(){                                var    sDPath = "../Calender.aspx";                 var    oWin = window.showModalDialog(sDPath, null, "dialogWidth:300px;dialogHeight:250px;help:0;status:0;scroll:0;center:1");  &nbs...

Web resources about - Client side set hidden field value not POSTing back - asp.net.client-side

Posting style - Wikipedia, the free encyclopedia
... is replied to in e-mail , Internet forums , or Usenet , the original can often be included, or "quoted", in a variety of different posting styles ...

Running Cross-Country, Posting On Facebook, And Writing A Book About It All
Running a marathon is tough, but what about running a marathon each day, for 93 days in a row, from California to Florida? Registered nurse Helene ...

Page updates not posting to my twitter... - Facebook-Hilfebereich - Facebook
Facebook is a social utility that connects people with friends and others who work, study and live around them. People use Facebook to keep ...

Posting to the Stream in Real Time with the Live Stream Box
Posting to the Stream in Real Time with the Live Stream Box

Facebook Careers Postings: Patents, Engineering, Mobile and More
... deal with patents, mobile, sales and recruiting. We gather this information from the company’s Careers Page, and this week there were no postings ...

Australian diplomat returned from posting after husband charged over child-sex allegations
One of Australia's top diplomats has returned early from an overseas posting after her spouse was arrested and charged with child sex offences.&nbsp; ...

Michelle Bridges blasted as 'irresponsible' for posting post natal workout tips
... she is a professional with 30 years of training behind her, and therefore not your typical new mum, Bridges has received backlash for posting ...

Man arrested for DUI after posting video of drinking while driving on Facebook
An Ohio man has been arrested for DUI after he posted a video of himself drinking while driving on Facebook.

Kardashians keep posting naked pictures of themselves
Do the Kardashians have any klothes? For folks so fashionable they sure love posing (and posting) nekkid. Is Kourtney Kardashian dating Justin ...

See a horrible accident? Bill would bar you from posting about it for an hour
(credit: frankieleon ) A new bill pending in the Kentucky state legislature would impose a ban of "at least one hour" on the online publication ...

Resources last updated: 1/22/2016 4:19:41 AM