This is a migrated thread and some comments may be shown as answers.

Cannot update hidden field value

1 Answer 398 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 24 Apr 2010, 02:02 PM
I have seen several posts on the web about this but, I have not been able to get any of the solutions to work.

I have a page that uses a RadSplitter to separate itself into two RadPanes. In the left pane is a RadTreeview. In the right pane is an ASP.NET Update Panel. It is the classic leftpane-treeview, rightpane-detail view setup.
I use context menus in the treeview to allow users to cut, copy, and paste items in the treeview, and all that works just great. If a user selects an item in the treeview, the right pane shows the detail page for that item and allows them to edit the details. That works just fine.
Here is the problem: If the user selects "Add Item" from the context menu of the treeview, I create a blank form in the detail page and allow them to fill out the form. When the "submit" button is clicked on the form, it is submitted and, when the call to the database is returns the newly created item's ID, I need to update the treeview to reflect the creation of the new item.
I created two hidden fields on my page to help me with all these operations.
hdnOperationType
hdnOperationSource

When the call to the database is returned, I set the value of hdnOperationType to "nodeadded", and I am trying to capture that in the "OnClientLoad" event of the treeview in the browser, so I can do the update of the treeview. But, when I check the value of the hdnOperationType field, after my server code has set it to "nodeadded", the value still reads the old value from the previous call back. The field is not updated. (from Googling this issue, I beleieve the client state is still pointing to a reference of an old version of hdnOperationType, and was not updated with a new reference).

Here is what my page definition looks like:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Exp.aspx.cs" Inherits="Exp" MasterPageFile="~/MasterPage.master" %> 
<%@ MasterType VirtualPath="~/MasterPage.master" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server" > 
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
        <script type="text/javascript">  
            //<![CDATA[                 
            function updateTreeView() {
                var update = document.getElementById('<%= hdnOperationType.ClientID %>');
                if (update) {
                    if (update.value == "nodeadded") {
                        update.value = "";
                        var newParent = document.getElementById('<%= hdnOperationSource.ClientID %>');
                        updateAffectedNode(newParent.value);
                    }
                    else {
                        if (update.value == "nodeedited") {
                            update.value = "";
                            var target = document.getElementById('<%= hdnOperationSource.ClientID %>');
                            updateAffectedNode(target.value);
                        }
                    }
                }
            }
            
            ...more javascript here
            //]]> 
        </script> 
    </telerik:RadCodeBlock> 
    <asp:HiddenField ID="hdnOperationType" runat="server" /> 
    <asp:HiddenField ID="hdnOperationSource" runat="server" /> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadTreeView1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="tvExplorer" /> 
                    <telerik:AjaxUpdatedControl ControlID="pnlDetail" /> 
                    <telerik:AjaxUpdatedControl ControlID="hdnOperationSource" /> 
                    <telerik:AjaxUpdatedControl ControlID="hdnOperationType" />          
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="UpdatePanel1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="tvExplorer" /> 
                    <telerik:AjaxUpdatedControl ControlID="pnlDetail" /> 
                    <telerik:AjaxUpdatedControl ControlID="hdnOperationSource" /> 
                    <telerik:AjaxUpdatedControl ControlID="hdnOperationType" />          
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadSplitter ID="RadSplitter1" CssClass="grid_12" Height="650" Width="100%" LiveResize="true"  runat="server">  
        <telerik:RadPane ID="pnlExplorer" Height="100%" Width="300" runat="server">  
            <telerik:RadTreeView ID="tvExplorer" runat="server" TabIndex="1" AccessKey="m"   
              OnClientLoad="updateTreeView" 
              OnClientContextMenuItemClicking="OnClientContextMenuItemClicking" 
              OnClientKeyPressing="OnClientKeyPressing" 
              OnNodeClick="tvExplorer_NodeClick" 
              OnContextMenuItemClick="tvExplorer_ContextMenuItemClick" 
            > 
                <WebServiceSettings Path="DataSvcProxy.asmx" Method="GetRadTreeViewNodes" /> 
                <Nodes> 
                    <telerik:RadTreeNode runat="server" Text="Root Node" Value="0" ClassID="0" PermClasses="0" ExpandMode="WebService" /> 
                </Nodes> 
            </telerik:RadTreeView> 
        </telerik:RadPane> 
        <telerik:RadSplitBar ID="RadSplitBar1" CollapseMode="Forward" runat="server" /> 
        <telerik:RadPane ID="pnlDetail" Height="100%" Width="100%" runat="server">  
            <asp:UpdatePanel ID="updDetail" runat="server" UpdateMode="Conditional" > 
                <ContentTemplate> 
                    <div class="emptyItem">  
                        Select an item in the left pane to view its information in this pane.  
                    </div> 
                </ContentTemplate> 
            </asp:UpdatePanel> 
        </telerik:RadPane> 
    </telerik:RadSplitter> 
</asp:Content> 

I have tried wrapping the declaration of the two hidden fields in an update panel and, in my server code, explicitly calling that update panel's "Update()" function but, that has no effect.

I am stumped. I thought I had a good grasp of ajax but this has stopped me in my tracks.

Any suggestions would really be appreciated.

Thanks.

Update: I have also tried registering the hidden fields by putting this code in the Page_Init routine:
        RadScriptManager.RegisterHiddenField(this, "hdnOperationType", "");
        RadScriptManager.RegisterHiddenField(this, "hdnOperationSource", "");
(I used the static member of the class because my RadScriptManager instance (RadScriptManager1) does not provide a RegisterHiddenField method.)
This has had no effect at all.

1 Answer, 1 is accepted

Sort by
0
Roger
Top achievements
Rank 1
answered on 24 Apr 2010, 09:54 PM
Disregard this thread.

I corrected some things listed in the original post and that has completely changed the issues I am addressing.

Thanks
Tags
Ajax
Asked by
Roger
Top achievements
Rank 1
Answers by
Roger
Top achievements
Rank 1
Share this question
or