title: Get hidden field values from codebehind
body: <p>I am trying to assign hiddenfield values as shown on my page_load:</p>
  
  <pre><code>If Session("tempDir") Is Nothing Then
      If Request.Files.Count &gt; 0 Then
          Dim tempDir As String
          tempDir = Path.GetRandomFileName()
          tempDir = tempDir.Substring(0, tempDir.LastIndexOf("."))
          IO.Directory.CreateDirectory(Server.MapPath("~/Uploads/" &amp; tempDir))
          IO.Directory.CreateDirectory(Server.MapPath("~/Downloads/" &amp; tempDir))
          Session.Add("tempDir", tempDir)
  
  
          currentDirectory.Value = Session("tempDir").ToString
  
          Dim chunk As Integer = If(Context.Request("chunk") IsNot Nothing, Integer.Parse(Context.Request("chunk")), 0)
          Dim fileName As String = If(Context.Request("name") IsNot Nothing, Context.Request("name"), String.Empty)
          myfilename = fileName
          Session.Add("filename", myfilename)
          finalfilename.Value = currentDirectory.Value &amp; fileName
  
          finalfilename.Value = Session("filename").ToString
          MsgBox(finalfilename.Value)
  
          workingDir.Value = Server.MapPath("~/Uploads/" &amp; tempDir)
          Session.Add("tempDir", workingDir.Value)
          MsgBox(workingDir.Value)
  
  
          waitFlag.Value = "True"
          Session.Add("flag", waitFlag.Value)
  
          waitFlag.Value = Session("flag").ToString
          MsgBox(waitFlag.Value)
  
          Dim fileUpload As HttpPostedFile = Context.Request.Files(0)
  
          Dim uploadPath = Context.Server.MapPath("~/uploads/" &amp; tempDir)
          Using fs = New FileStream(Path.Combine(uploadPath, fileName), If(chunk = 0, FileMode.Create, FileMode.Append))
              Dim buffer = New Byte(fileUpload.InputStream.Length - 1) {}
              fileUpload.InputStream.Read(buffer, 0, buffer.Length)
  
              fs.Write(buffer, 0, buffer.Length)
          End Using
      End If
  End If
  </code></pre>
  
  <p>These are my html input hidden fields:</p>
  
  <pre><code>&lt;input type="hidden" id="workingDir" runat="server"/&gt;
  &lt;input type="hidden" id="finalfilename" runat="server"/&gt;
  &lt;input type="hidden" id="waitFlag"  runat="server"/&gt;
  &lt;input id="currentDirectory" type="hidden" runat="server"/&gt;
  </code></pre>
  
  <p>This is my ajax call where I get all the hidden field values as undefined:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
       $('#btnconvert').click(function () {
           var wd = $('#workingDir').val();
           alert(wd);
           var fn = $('#finalfilename').val();
           alert(fn);
           var bf = $('#waitFlag').val();
           alert(bf);
           $.ajax({
               type: "POST",
               url: "Default.aspx/ProcessFiles",
               data: "{'workingDir':'" + wd + "', 'finalfilename':'" + fn + "', 'waitFlag':'" + bf + "'}",
               contentType: "application/json; charset=utf-8",
               dataType: "json",
               success: function (data) {
                   alert("success");
               },
               error: function (data) {
                   alert("fail");
               }
           });
       });
    &lt;/script&gt;
  </code></pre>
  
  <p>can anyone point out me where am I going wrong ?</p>