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 |
![]() |
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 |
![]() |
hi josh, no, its a server-side hidden-field
frustrated... on so many levels
![]() |
0 |
![]() |
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 |
![]() |
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 |
![]() |
![]() |
0 |
![]() |
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 |
![]() |
you took the words out of my keyboard NC01 ;-) its a hidden field, setting a visible attrib would be somewhat nonsensical!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...
frustrated... on so many levels
![]() |
0 |
![]() |
I think that some of these people just like to post things
NC...
![]() |
0 |
![]() |
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 |
![]() |
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 |
![]() |
anyone?
cheers,
dan
frustrated... on so many levels
![]() |
0 |
![]() |
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 |
![]() |
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 |
![]() |
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
Cheers,
Sunny
![]() |
0 |
![]() |
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 |
![]() |
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 |
![]() |
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.htmlNC...
![]() |
0 |
![]() |
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:
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 |
![]() |
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 |
![]() |