Ritu
Ritu

Reputation: 27

Getting null value of the hidden field at server-side

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

Upvotes: 2

Views: 5075

Answers (2)

greko
greko

Reputation: 225

I am using hidden fields with UpdatePanels ( hidden field must be send back to server to use it in partial postback ) and you can try set EnableViewState = true ( whole page post back ).

aspx:

        <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load" UpdateMode="Conditional" ChildrenAsTriggers="True">
        <ContentTemplate>
            <asp:HiddenField runat="server" ID="LinesBack" value="0"/>

       <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="10" AssociatedUpdatePanelID="UpdatePanel1">
                <ProgressTemplate>
                    <img id="spinner" alt="spinner" src="../Pictures/spinner_30x30.gif" />
                </ProgressTemplate>
            </asp:UpdateProgress>
            <div id="Back" class="NewresultPanel" runat="server" ></div>
        </ContentTemplate>
    </asp:UpdatePanel>

html:

var a = document.getElementById('<%= LinesBack.ClientID %>').value;

cs:

            LinesBack.Value = CountRows.ToString();

Upvotes: 1

rahul
rahul

Reputation: 187030

You have to set runat="server" attribute for the hidden field to access it in server side code that you have posted.

Something like

HTML

<input type="hidden" id="hidTest" runat="server" />

server side code

hidTest.Value;

Upvotes: 0

Related Questions